description: A robot cleaner is placed on the floor of a rectangle room, surrounded by walls. The floor consists of n rows and m columns. The rows of the floor are numbered from 1 to n from top to bottom, and columns of the floor are numbered from 1 to m from left to right. The cell on the intersection of the r-th row and the c-th column is denoted as (r,c). The initial position of the robot is (r_b, c_b).
  
  In one second, the robot moves by dr rows and dc columns, that is, after one second, the robot moves from the cell (r, c) to (r + dr, c + dc). Initially dr = 1, dc = 1. If there is a vertical wall (the left or the right walls) in the movement direction, dc is reflected before the movement, so the new value of dc is -dc. And if there is a horizontal wall (the upper or lower walls), dr is reflected before the movement, so the new value of dr is -dr.
  
  Each second (including the moment before the robot starts moving), the robot cleans every cell lying in the same row or the same column as its position. There is only one dirty cell at (r_d, c_d). The job of the robot is to clean that dirty cell.
  
  <image> Illustration for the first example. The blue arc is the robot. The red star is the target dirty cell. Each second the robot cleans a row and a column, denoted by yellow stripes.
  
  Given the floor size n and m, the robot's initial position (r_b, c_b) and the dirty cell's position (r_d, c_d), find the time for the robot to do its job.
  
  Input
  
  Each test contains multiple test cases. The first line contains the number of test cases t (1 ≤ t ≤ 10^4). Description of the test cases follows.
  
  A test case consists of only one line, containing six integers n, m, r_b, c_b, r_d, and c_d (1 ≤ n, m ≤ 100, 1 ≤ r_b, r_d ≤ n, 1 ≤ c_b, c_d ≤ m) — the sizes of the room, the initial position of the robot and the position of the dirt cell.
  
  Output
  
  For each test case, print an integer — the time for the robot to clean the dirty cell. We can show that the robot always cleans the dirty cell eventually.
  
  Example
  
  Input
  
  
  5
  10 10 6 1 2 8
  10 10 9 9 1 1
  9 8 5 6 2 1
  6 9 2 2 5 8
  2 2 1 1 2 1
  
  
  Output
  
  
  7
  10
  9
  3
  0
  
  Note
  
  In the first example, the floor has the size of 10× 10. The initial position of the robot is (6, 1) and the position of the dirty cell is (2, 8). See the illustration of this example in the problem statement.
  
  In the second example, the floor is the same, but the initial position of the robot is now (9, 9), and the position of the dirty cell is (1, 1). In this example, the robot went straight to the dirty cell and clean it. 
  
  <image>
  
  In the third example, the floor has the size 9 × 8. The initial position of the robot is (5, 6), and the position of the dirty cell is (2, 1). 
  
  <image>
  
  In the fourth example, the floor has the size 6 × 9. The initial position of the robot is (2, 2) and the position of the dirty cell is (5, 8). 
  
  <image>
  
  In the last example, the robot was already standing in the same column as the dirty cell, so it can clean the cell right away. 
  
  <image>
solution: 
  import java.io.BufferedReader;
  import java.io.IOException;
  import java.io.InputStreamReader;
  import java.io.OutputStreamWriter;
  import java.io.PrintWriter;
  import java.util.StringTokenizer;
  
  public class A_Robot_Cleaner {
   
      static Scanner in=new Scanner();
      
      static PrintWriter out=new PrintWriter( new OutputStreamWriter(System.out) );
      
      static int testCases,n,m,rb,cb,rd,cd;
      
      static void solve(){
          
          int ans=0,st=1,st2=1;
          
          while(true){
              
          if(rb == rd || cb == cd) break;
          if(rb + st > n || rb + st < 1) st *= -1;
          if(cb + st2 > m || cb + st2 < 1) st2 *= -1;
          rb += st;
          cb += st2;
          ans++;
              
          }
          
          out.println(ans);
          out.flush();
          
      }
      
      public static void main(String[] amit) throws IOException {
          
          testCases=in.nextInt();
          
          for(int t=0;t<testCases;t++){
              
              n=in.nextInt();
              m=in.nextInt();
              rb=in.nextInt();
              cb=in.nextInt();
              rd=in.nextInt();
              cd=in.nextInt();
              
              solve();
              
          }
          
          in.close();
          
      }
      
      static String sum(String a,String b){
          
          StringBuilder ans=new StringBuilder();
          
          int n1=a.length(),m=b.length();
          
          if(n1>m ){
              
              String t=a;
              a=b;
              b=t;
              
          }
          
          n1=a.length();
          m=b.length();
          
          StringBuilder str1=new StringBuilder(a).reverse();
          StringBuilder str2=new StringBuilder(b).reverse();
          
          char first[]=str1.toString().toCharArray();
          char second[]=str2.toString().toCharArray();
          
          int carry=0;
          
          for(int i=0;i<n1;i++){
              
              int sum=(first[i]-'0')+(second[i]-'0')+carry;
              
              ans.append(sum%10 );
              
              carry=sum/10;
              
          }
          
          for(int i=n1;i<m;i++){
              
             int sum=(second[i]-'0')+carry;
             
             ans.append(sum%10 );
              
             sum/=10;
             
          }
          
          if(carry>0){
              
              ans.append(carry);
              
          }
          
          ans.reverse();
          
          return ans.toString();
          
      }
      
      static String mul(String num1, String num2)
  {
      int len1 = num1.length();
      int len2 = num2.length();
      if (len1 == 0 || len2 == 0)
          return "0";
   
      
      int result[] = new int[len1 + len2];
   
      
      int i_n1 = 0;
      int i_n2 = 0;
       
    
      for (int i = len1 - 1; i >= 0; i--)
      {
          int carry = 0;
          int n1 = num1.charAt(i) - '0';
   
          
          i_n2 = 0;
           
                   
          for (int j = len2 - 1; j >= 0; j--)
          {
              
              int n2 = num2.charAt(j) - '0';
   
             
              int sum = n1 * n2 + result[i_n1 + i_n2] + carry;
   
              
              carry = sum / 10;
   
           
              result[i_n1 + i_n2] = sum % 10;
   
              i_n2++;
          }
   
         
          if (carry > 0)
              result[i_n1 + i_n2] += carry;
   
         
          i_n1++;
      }
   
     
      int i = result.length - 1;
      while (i >= 0 && result[i] == 0)
      i--;
   
     
      if (i == -1)
      return "0";
   
      
      String s = "";
       
      while (i >= 0)
          s += (result[i--]);
   
      return s;
  }
      
      static int multiply(int x, int res[], int res_size) {
   
      
      int carry = 0;
   
      
      for (int i = 0; i < res_size; i++) {
      int prod = res[i] * x + carry;
   
      
      res[i] = prod % 10;
   
     
      carry = prod / 10;
      }
   
     
      while (carry > 0) {
      res[res_size] = carry % 10;
      carry = carry / 10;
      res_size++;
      }
      return res_size;
  }
   
  
  static long power(int x, int n) {
       
      int MAX = 100000;
      
      
      if(n == 0 ){
     
          
      return 1;
  }
      int res[] = new int[MAX];
      int res_size = 0;
      int temp = x;
   
     
      while (temp != 0) {
      res[res_size++] = temp % 10;
      temp = temp / 10;
      }
   
      
      for (int i = 2; i <= n; i++)
      res_size = multiply(x, res, res_size);
   
     StringBuilder sb=new StringBuilder();
      
      for (int i = res_size - 1; i >= 0; i--)
      sb.append(res[i]);
      
      return Long.parseLong(sb.toString());
      
  }
                    
     static class Node<T>{
      
      T data;
      
      Node<T> next;
  
      public Node() {
      
          this.next=null;
      
      }
  
      public Node(T data) {
          
          this.data = data;
      
          this.next=null;
          
      }
  
      public T getData() {
          return data;
      }
  
      public void setData(T data) {
          this.data = data;
      }
  
      public Node<T> getNext() {
          return next;
      }
  
      public void setNext(Node<T> next) {
          this.next = next;
      }
      
      @Override
      public String toString(){
          
          return this.getData().toString()+"  ";
          
      }
      
  }
  
     static class ArrayList<T>{
             
      Node<T> head,tail;
      
      int len;
  
      public ArrayList() {
      
      this.head=null;    
          
      this.tail=null;
      
      this.len=0;
      
      }
      
      int size(){
          
          return len;
          
      }
      
      boolean isEmpty(){
          
          return len==0;
          
      }
      
      int indexOf(T data){
          
          if( isEmpty() ){
              
              throw new ArrayIndexOutOfBoundsException();
              
          }
          
          Node<T> temp=head;
          
          int index=0,i=0;
          
          while(temp!=null){
              
              if( temp.getData()==data ){
                  
                  index=i;
                  
              }
              
              i++;
              
              temp=temp.getNext();
              
          }
          
          return index;
          
      }
      
      void add(T data){
          
          Node<T> newNode=new Node<>(data);
          
          if( isEmpty() ){
              
              head=newNode;
              
              tail=newNode;
              
              len++;
              
          }else{
          
          tail.setNext(newNode);
              
          tail=newNode;
          
          len++;
          
          }
          
      }
      
      void see(){
          
          if( isEmpty() ){
              
              throw new ArrayIndexOutOfBoundsException();
              
          }
          
          Node<T> temp=head;
          
          while( temp!=null ){
              
              out.print(temp.getData().toString()+" ");
              out.flush();
              
              temp=temp.getNext();
              
          }
          
          out.println();
          out.flush();
          
      }
              
      void inserFirst(T data){
          
          Node<T> newNode=new Node<>(data);
          
          Node<T> temp=head;
          
          if( isEmpty() ){
              
              head=newNode;
              tail=newNode;
              
              len++;
              
          }else{
              
              newNode.setNext(temp);
              
              head=newNode;
              
              len++;
              
          }
          
      }
      
      T get(int index){
          
          if( isEmpty() || index>=len ){
              
              throw new ArrayIndexOutOfBoundsException();
              
          }
          
          Node<T> temp=head;
          
          if(index==0){
              
              return temp.getData();
              
          }
          
          int i=0;
          
          T data=null;
          
          while(temp!=null){
              
              if( i==index ){
                  
                  data=temp.getData();
                  
              }
              
              i++;
              
              temp=temp.getNext();
              
          }
          
          return data;
          
      }
      
      void addAt(T data,int index){
          
          if( index>=len ){
              
              throw new ArrayIndexOutOfBoundsException();
              
          }
          
          Node<T> newNode=new Node<>(data);
          
          int i=0;
          
          Node<T> temp=head;
          
          while( temp.next!=null ){
              
              if(i==index){
                  
                  newNode.setNext(temp.next);
                  
                  temp.next=newNode;
                  
              }
              
              i++;
              
              temp=temp.getNext();
              
          }
          
      //    temp.setNext(temp);
          
          len++;
          
      }
      
      T popFront(){
          
          if( isEmpty() ){
              
              throw new ArrayIndexOutOfBoundsException();
              
          }
          
          T data=head.getData();
          
          if( head==tail ){
              
              head=null;
              tail=null;
              
          }else{
              
              head=head.getNext();
              
          }
          
          len--;
          
          return data;
          
      }
      
      void removeAt(int index){
          
          if( index>=len ){
              
              throw new ArrayIndexOutOfBoundsException();
              
          }
          
          if(index==0){
              
              this.popFront();
              
              return;
              
          }
          
          Node<T> temp=head;
          
          int i=0;
          
          Node<T> n=new Node<>();
          
          while(temp!=null){
              
              if(i==index){
                  
                  n.next=temp.next;
                  
                  temp.next=n;
                  
                  break;
                  
              }
              
              i++;
              
              n=temp;
              
              temp=temp.getNext();
              
          }
          
          tail=n;
          
          --len;
          
      }
      
      void clearAll(){
          
          this.head=null;
          this.tail=null;
          
      }
         
     }
     
      static long gcd(long a, long b)
      {
        if (b == 0)
          return a;
        return gcd(b, a % b);
      }
  	
     static void merge(long a[],int left,int right,int mid){
          
          int n1=mid-left+1,n2=right-mid;
          
          long L[]=new long[n1];
          
          long R[]=new long[n2];
          
          for(int i=0;i<n1;i++){
              
              L[i]=a[left+i];
              
          }
          
          for(int i=0;i<n2;i++){
              
              R[i]=a[mid+1+i];
              
          }
          
          int i=0,j=0,k1=left;
          
          while(i<n1 && j<n2){
              
              if( L[i]<=R[j] ){
                  
                  a[k1]=L[i];
                  
                  i++;
                  
              }else{
                  
                  a[k1]=R[j];
                  
                  j++;
                  
              }
              
              k1++;
              
          }
          
          while(i<n1){
              
              a[k1]=L[i];
              
              i++;
              
              k1++;
              
          }
          
          while(j<n2){
              
              a[k1]=R[j];
              
              j++;
              k1++;
              
          }
          
      }
      
      static void sort(long a[],int left,int right){
          
          if(left>=right){
              
              return;
              
          }
          
          int mid=(left+right)/2;
          
          sort(a,left,mid);
          
          sort(a,mid+1,right);
          
          merge(a,left,right,mid);
          
      }
  	
      static class Node1<T>{
          
          T data;
          
          Node1 next;
  
          public Node1(T data) {
              this.data = data;
          
              this.next=null;
              
          }
  
          public T getData() {
              return data;
          }
  
          public void setData(T data) {
              this.data = data;
          }
  
          public Node1 getNext() {
              return next;
          }
  
          public void setNext(Node1 next) {
              this.next = next;
          }
          
      }
      
      static class Stack<T>{
          
          int len;
          
          Node1<T> node;
  
          public Stack() {
          
              len=0;
              
              node=null;
              
          }
          
          boolean isEmpty(){
              
              return len==0;
              
          }
          
          int size(){
              
              return len;
              
          }
          
          void push(T data){
              
              Node1<T> temp=new Node1<>(data);
              
              temp.setNext(this.node);
              
              node=temp;
              
              len++;
              
          }
          
          T top(){
              
              if( isEmpty() ){
                  
                  throw new ArrayIndexOutOfBoundsException();
                  
              }
              
              return this.node.getData();
              
          }
          
          T pop(){
              
              if( isEmpty() ){
                  
                  throw new ArrayIndexOutOfBoundsException();
                  
              }
              
              T data=this.node.getData();
              
              this.node=this.node.getNext();
              
              len--;
              
              return data;
              
          }
          
      }
      
  	  static class Scanner{
          
          BufferedReader in;
          StringTokenizer st;
  
          public Scanner() {
          
              in=new BufferedReader( new InputStreamReader(System.in) );
              
          }
          
          String next() throws IOException{
              
              while(st==null || !st.hasMoreElements()){
                  
                  st=new StringTokenizer(in.readLine());
                  
              }
              
              return st.nextToken();
              
          }
          
          int nextInt() throws IOException{
              
              return Integer.parseInt(next());
              
          }
          
          long nextLong() throws IOException{
              
              return Long.parseLong(next());
              
          }
          
          String nextLine() throws IOException{
              
              return in.readLine();
              
          }
          
          char nextChar() throws IOException{
              
              return next().charAt(0);
              
          }
          
          double nextDouble() throws IOException{
              
              return Double.parseDouble(next());
              
          }
          
          float nextFloat() throws IOException{
              
              return Float.parseFloat(next());
              
          }
          
          boolean nextBoolean() throws IOException{
              
              return Boolean.parseBoolean(next());
              
          }
          
          void close() throws IOException{
              
              in.close();
              
          }
          
      }
  	
  }
  /*
  
  5
  10 10 6 1 2 8
  10 10 9 9 1 1
  9 8 5 6 2 1
  6 9 2 2 5 8
  2 2 1 1 2 1
  
  
  */