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.*;
  import java.util.*;
  
  public final class Main {
  
      static PrintWriter out = new PrintWriter(System.out);
      static FastReader in = new FastReader();
      static Pair[] moves = new Pair[]{new Pair(-1, 0), new Pair(0, 1), new Pair(1, 0), new Pair(0, -1)};
      static int mod = (int) (1e9 + 7);
      static int mod2 = 998244353;
  
      public static void main(String[] args) {
          int tt = i();
          while (tt-- > 0) {
              solve();
          }
          out.flush();
      }
  
      public static void solve() {
          int n = i();
          int m = i();
          int a = i();
          int b = i();
          int x = i();
          int y = i();
          int t = 0;
  
          int i = 1;
          int j = 1;
          while (true) {
              if (a == x || b == y) {
                  break;
              }
              if (a + i > n || a + i < 0) {
                  i = -i;
              }
              if (b + j > m || b + j < 0) {
                  j = -j;
              }
              a = a + i;
              b = b + j;
              t++;
          }
  
          out.println(t);
  
  
      }
  
      static long[] pre(int[] a) {
          long[] pre = new long[a.length + 1];
          pre[0] = 0;
          for (int i = 0; i < a.length; i++) {
              pre[i + 1] = pre[i] + a[i];
          }
          return pre;
      }
  
      static long[] pre(long[] a) {
          long[] pre = new long[a.length + 1];
          pre[0] = 0;
          for (int i = 0; i < a.length; i++) {
              pre[i + 1] = pre[i] + a[i];
          }
          return pre;
      }
  
      static void print(char A[]) {
          for (char c : A) {
              out.print(c);
          }
          out.println();
      }
  
      static void print(boolean A[]) {
          for (boolean c : A) {
              out.print(c + " ");
          }
          out.println();
      }
  
      static void print(int A[]) {
          for (int c : A) {
              out.print(c + " ");
          }
          out.println();
      }
  
      static void print(long A[]) {
          for (long i : A) {
              out.print(i + " ");
          }
          out.println();
      }
  
      static void print(List<Integer> A) {
          for (int a : A) {
              out.print(a + " ");
          }
      }
  
      static int i() {
          return in.nextInt();
      }
  
      static long l() {
          return in.nextLong();
      }
  
      static double d() {
          return in.nextDouble();
      }
  
      static String s() {
          return in.nextLine();
      }
  
      static String c() {
          return in.next();
      }
  
      static int[][] inputWithIdx(int N) {
          int A[][] = new int[N][2];
          for (int i = 0; i < N; i++) {
              A[i] = new int[]{i, in.nextInt()};
          }
          return A;
      }
  
      static int[] input(int N) {
          int A[] = new int[N];
          for (int i = 0; i < N; i++) {
              A[i] = in.nextInt();
          }
          return A;
      }
  
      static long[] inputLong(int N) {
          long A[] = new long[N];
          for (int i = 0; i < A.length; i++) {
              A[i] = in.nextLong();
          }
          return A;
      }
  
      static int GCD(int a, int b) {
          if (b == 0) {
              return a;
          } else {
              return GCD(b, a % b);
          }
      }
  
      static long GCD(long a, long b) {
          if (b == 0) {
              return a;
          } else {
              return GCD(b, a % b);
          }
      }
  
      static long LCM(int a, int b) {
          return (long) a / GCD(a, b) * b;
      }
  
      static long LCM(long a, long b) {
          return a / GCD(a, b) * b;
      }
  
      static void shuffle(int[] arr) {
          for (int i = 0; i < arr.length; i++) {
              int rand = (int) (Math.random() * arr.length);
              int temp = arr[rand];
              arr[rand] = arr[i];
              arr[i] = temp;
          }
      }
  
      static void shuffleAndSort(int[] arr) {
          for (int i = 0; i < arr.length; i++) {
              int rand = (int) (Math.random() * arr.length);
              int temp = arr[rand];
              arr[rand] = arr[i];
              arr[i] = temp;
          }
          Arrays.sort(arr);
      }
  
      static void shuffleAndSort(int[][] arr, Comparator<? super int[]> comparator) {
          for (int i = 0; i < arr.length; i++) {
              int rand = (int) (Math.random() * arr.length);
              int[] temp = arr[rand];
              arr[rand] = arr[i];
              arr[i] = temp;
          }
          Arrays.sort(arr, comparator);
      }
  
      static void shuffleAndSort(long[] arr) {
          for (int i = 0; i < arr.length; i++) {
              int rand = (int) (Math.random() * arr.length);
              long temp = arr[rand];
              arr[rand] = arr[i];
              arr[i] = temp;
          }
          Arrays.sort(arr);
      }
  
      static boolean isPerfectSquare(double number) {
          double sqrt = Math.sqrt(number);
          return ((sqrt - Math.floor(sqrt)) == 0);
      }
  
      static void swap(int A[], int a, int b) {
          int t = A[a];
          A[a] = A[b];
          A[b] = t;
      }
  
      static void swap(char A[], int a, int b) {
          char t = A[a];
          A[a] = A[b];
          A[b] = t;
      }
  
      static long pow(long a, long b, int mod) {
          long pow = 1;
          long x = a;
          while (b != 0) {
              if ((b & 1) != 0) {
                  pow = (pow * x) % mod;
              }
              x = (x * x) % mod;
              b /= 2;
          }
          return pow;
      }
  
      static long pow(long a, long b) {
          long pow = 1;
          long x = a;
          while (b != 0) {
              if ((b & 1) != 0) {
                  pow *= x;
              }
              x = x * x;
              b /= 2;
          }
          return pow;
      }
  
      static long modInverse(long x, int mod) {
          return pow(x, mod - 2, mod);
      }
  
      static boolean isPrime(long N) {
          if (N <= 1) {
              return false;
          }
          if (N <= 3) {
              return true;
          }
          if (N % 2 == 0 || N % 3 == 0) {
              return false;
          }
          for (int i = 5; i * i <= N; i = i + 6) {
              if (N % i == 0 || N % (i + 2) == 0) {
                  return false;
              }
          }
          return true;
      }
  
      public static String reverse(String str) {
          if (str == null) {
              return null;
          }
          return new StringBuilder(str).reverse().toString();
      }
  
      public static void reverse(int[] arr) {
          for (int i = 0; i < arr.length / 2; i++) {
              int tmp = arr[i];
              arr[arr.length - 1 - i] = tmp;
              arr[i] = arr[arr.length - 1 - i];
          }
      }
  
      public static String repeat(char ch, int repeat) {
          if (repeat <= 0) {
              return "";
          }
          final char[] buf = new char[repeat];
          for (int i = repeat - 1; i >= 0; i--) {
              buf[i] = ch;
          }
          return new String(buf);
      }
  
      public static int[] manacher(String s) {
          char[] chars = s.toCharArray();
          int n = s.length();
          int[] d1 = new int[n];
          for (int i = 0, l = 0, r = -1; i < n; i++) {
              int k = (i > r) ? 1 : Math.min(d1[l + r - i], r - i + 1);
              while (0 <= i - k && i + k < n && chars[i - k] == chars[i + k]) {
                  k++;
              }
              d1[i] = k--;
              if (i + k > r) {
                  l = i - k;
                  r = i + k;
              }
          }
          return d1;
      }
  
      public static int[] kmp(String s) {
          int n = s.length();
          int[] res = new int[n];
          for (int i = 1; i < n; ++i) {
              int j = res[i - 1];
              while (j > 0 && s.charAt(i) != s.charAt(j)) {
                  j = res[j - 1];
              }
              if (s.charAt(i) == s.charAt(j)) {
                  ++j;
              }
              res[i] = j;
          }
          return res;
      }
  }
  
  class Pair {
  
      int i;
      int j;
  
      Pair(int i, int j) {
          this.i = i;
          this.j = j;
      }
  
      @Override
      public boolean equals(Object o) {
          if (this == o) {
              return true;
          }
          if (o == null || getClass() != o.getClass()) {
              return false;
          }
          Pair pair = (Pair) o;
          return i == pair.i && j == pair.j;
      }
  
      @Override
      public int hashCode() {
          return Objects.hash(i, j);
      }
  }
  
  class ThreePair {
  
      int i;
      int j;
      int k;
  
      ThreePair(int i, int j, int k) {
          this.i = i;
          this.j = j;
          this.k = k;
      }
  
      @Override
      public boolean equals(Object o) {
          if (this == o) {
              return true;
          }
          if (o == null || getClass() != o.getClass()) {
              return false;
          }
          ThreePair pair = (ThreePair) o;
          return i == pair.i && j == pair.j && k == pair.k;
      }
  
      @Override
      public int hashCode() {
          return Objects.hash(i, j);
      }
  }
  
  class FastReader {
  
      BufferedReader br;
      StringTokenizer st;
  
      public FastReader() {
          br = new BufferedReader(new InputStreamReader(System.in));
      }
  
      String next() {
          while (st == null || !st.hasMoreElements()) {
              try {
                  st = new StringTokenizer(br.readLine());
              } catch (IOException e) {
                  e.printStackTrace();
              }
          }
          return st.nextToken();
      }
  
      int nextInt() {
          return Integer.parseInt(next());
      }
  
      long nextLong() {
          return Long.parseLong(next());
      }
  
      double nextDouble() {
          return Double.parseDouble(next());
      }
  
      String nextLine() {
          String str = "";
          try {
              str = br.readLine();
          } catch (IOException e) {
              e.printStackTrace();
          }
          return str;
      }
  }
  
  class Node {
  
      int val;
  
      public Node(int val) {
          this.val = val;
      }
  }
  
  
  class ST {
  
      int n;
      Node[] st;
  
      ST(int n) {
          this.n = n;
          st = new Node[4 * Integer.highestOneBit(n)];
      }
  
      void build(Node[] nodes) {
          build(0, 0, n - 1, nodes);
      }
  
      private void build(int id, int l, int r, Node[] nodes) {
          if (l == r) {
              st[id] = nodes[l];
              return;
          }
          int mid = (l + r) >> 1;
          build((id << 1) + 1, l, mid, nodes);
          build((id << 1) + 2, mid + 1, r, nodes);
          st[id] = comb(st[(id << 1) + 1], st[(id << 1) + 2]);
      }
  
      void update(int i, Node node) {
          update(0, 0, n - 1, i, node);
      }
  
      private void update(int id, int l, int r, int i, Node node) {
          if (i < l || r < i) {
              return;
          }
          if (l == r) {
              st[id] = node;
              return;
          }
          int mid = (l + r) >> 1;
          update((id << 1) + 1, l, mid, i, node);
          update((id << 1) + 2, mid + 1, r, i, node);
          st[id] = comb(st[(id << 1) + 1], st[(id << 1) + 2]);
      }
  
      Node get(int x, int y) {
          return get(0, 0, n - 1, x, y);
      }
  
      private Node get(int id, int l, int r, int x, int y) {
          if (x > r || y < l) {
              return new Node(0);
          }
          if (x <= l && r <= y) {
              return st[id];
          }
          int mid = (l + r) >> 1;
          return comb(get((id << 1) + 1, l, mid, x, y), get((id << 1) + 2, mid + 1, r, x, y));
      }
  
      Node comb(Node a, Node b) {
          if (a == null) {
              return b;
          }
          if (b == null) {
              return a;
          }
          return new Node(a.val | b.val);
      }
  }