Captain Marmot wants to prepare a huge and important battle against his enemy, Captain Snake. For this battle he has n regiments, each consisting of 4 moles.

Initially, each mole i (1 ≤ i ≤ 4n) is placed at some position (xi, yi) in the Cartesian plane. Captain Marmot wants to move some moles to make the regiments compact, if it's possible.

Each mole i has a home placed at the position (ai, bi). Moving this mole one time means rotating his position point (xi, yi) 90 degrees counter-clockwise around it's home point (ai, bi).

A regiment is compact only if the position points of the 4 moles form a square with non-zero area.

Help Captain Marmot to find out for each regiment the minimal number of moves required to make that regiment compact, if it's possible.

Input

The first line contains one integer n (1 ≤ n ≤ 100), the number of regiments.

The next 4n lines contain 4 integers xi, yi, ai, bi ( - 104 ≤ xi, yi, ai, bi ≤ 104).

Output

Print n lines to the standard output. If the regiment i can be made compact, the i-th line should contain one integer, the minimal number of required moves. Otherwise, on the i-th line print "-1" (without quotes).

Examples

Input

4
1 1 0 0
-1 1 0 0
-1 1 0 0
1 -1 0 0
1 1 0 0
-2 1 0 0
-1 1 0 0
1 -1 0 0
1 1 0 0
-1 1 0 0
-1 1 0 0
-1 1 0 0
2 2 0 1
-1 0 0 -2
3 0 0 -2
-1 1 -2 0


Output

1
-1
3
3

Note

In the first regiment we can move once the second or the third mole.

We can't make the second regiment compact.

In the third regiment, from the last 3 moles we can move once one and twice another one.

In the fourth regiment, we can move twice the first mole and once the third mole.
#include <bits/stdc++.h>
using namespace std;
struct comparator {
  bool operator()(long long int i, long long int j) { return i > j; }
};
bool sortpair(pair<long long int, long long int> &a,
              pair<long long int, long long int> &b) {
  return (b.first - b.second) > (a.first - a.second);
}
long long int gcd(long long int a, long long int b) {
  if (a == 0) {
    return b;
  }
  return gcd(b % a, a);
}
long long int min(long long int a, long long int b) { return a > b ? b : a; }
long long int min(long long int a, long long int b, long long int c) {
  if (a <= b && a <= c) {
    return a;
  } else if (b <= a && b <= c) {
    return b;
  } else {
    return c;
  }
}
long long int max(long long int a, long long int b) { return a > b ? a : b; }
long long int lcm(long long int a, long long int b) {
  return (a * b / gcd(a, b));
}
bool check(long long int x) {
  while (x % 2 == 0) {
    x /= 2;
  }
  while (x % 3 == 0) {
    x /= 3;
  }
  if (x != 1) {
    return false;
  }
  return true;
}
long long int ans(int num, int n) {
  if (n == 1) {
    return num;
  } else if (n == 2) {
    return num + 1;
  } else if (n == 3) {
    return num + 2;
  } else if (n % 3 == 0) {
    return ans(num + 2, (n - 1) / 2);
  } else if (n % 2 == 0) {
    return ans(num + 1, n / 2);
  }
}
vector<long long int> getprimes() {
  vector<long long int> pl(101, 1);
  for (int i = 2; i <= 100; i++) {
    if (pl[i] == 1) {
      for (int j = 2 * i; j <= 100; j += i) {
        pl[j] = 0;
      }
    }
  }
  return pl;
}
long long int ans(int n) {
  if (n == 0) {
    return 1;
  } else if (n == 1 || n == 2) {
    return 0;
  } else if (n < 0) {
    return 0;
  } else {
    return (ans(n - 7) | ans(n - 3));
  }
}
long long int primefactorise(int n) {
  if (n == 1) {
    return 1;
  }
  long long int ans = n;
  while (n % 2 == 0) {
    n = n / 2;
    if (n != 1) {
      ans += n;
    }
  }
  for (int i = 3; i <= sqrt(n); i = i + 2) {
    while (n % i == 0) {
      n = n / i;
      if (n != 1) {
        ans += n;
      }
    }
  }
  ans += 1;
  return ans;
}
long long int power(long long int a, long long int b) {
  long long int ans = 1;
  while (b > 0) {
    if (b % 2 == 1) {
      ans *= a;
      ans = ans % 1000000009;
    }
    b /= 2;
    a *= a;
    a = a % 1000000009;
  }
  return ans % 1000000009;
}
bool check(long long int n, long long int a, long long int b) {
  while (n > 0) {
    if (n % 10 == a || n % 10 == b) {
      n /= 10;
    } else {
      return false;
    }
  }
  return true;
}
bool digsum(long long int n) {
  int sum = 0;
  while (n > 0) {
    sum += (n % 10);
    n /= 10;
  }
  if (sum == 10) {
    return true;
  }
  return false;
}
pair<long long int, long long int> rotate(long long int p[4][4],
                                          long long int times,
                                          long long int index) {
  long long int x, y;
  x = p[index][0] - p[index][2];
  y = p[index][1] - p[index][3];
  if (times == 0) {
    return make_pair(x + p[index][2], y + p[index][3]);
  } else if (times == 1) {
    return make_pair(-y + p[index][2], x + p[index][3]);
  } else if (times == 2) {
    return make_pair(-x + p[index][2], -y + p[index][3]);
  } else {
    return make_pair(y + p[index][2], -x + p[index][3]);
  }
}
long long int dist(long long int x1, long long int y1, long long int x2,
                   long long int y2) {
  return ((x2 - x1) * (x2 - x1)) + ((y2 - y1) * (y2 - y1));
}
bool checkifsquare(long long int x1, long long int y1, long long int x2,
                   long long int y2, long long int x3, long long int y3,
                   long long int x4, long long int y4) {
  long long int distance[6];
  distance[0] = dist(x1, y1, x2, y2);
  distance[1] = dist(x1, y1, x3, y3);
  distance[2] = dist(x1, y1, x4, y4);
  distance[3] = dist(x2, y2, x3, y3);
  distance[4] = dist(x2, y2, x4, y4);
  distance[5] = dist(x3, y3, x4, y4);
  sort(distance, distance + 6);
  if (distance[0] == distance[3] && distance[5] == distance[4] &&
      distance[4] != distance[3]) {
    return true;
  }
  return false;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int n, m;
  cin >> n;
  long long int p[4][4];
  for (int t = 0; t < n; t++) {
    for (int z = 0; z < 4; z++) {
      cin >> p[z][0] >> p[z][1] >> p[z][2] >> p[z][3];
    }
    long long int min = -1;
    for (int i = 0; i < 4; i++) {
      for (int j = 0; j < 4; j++) {
        for (int k = 0; k < 4; k++) {
          for (int l = 0; l < 4; l++) {
            long long int x1, y1, x2, y2, x3, y3, x4, y4;
            x1 = rotate(p, i, 0).first;
            y1 = rotate(p, i, 0).second;
            x2 = rotate(p, j, 1).first;
            y2 = rotate(p, j, 1).second;
            x3 = rotate(p, k, 2).first;
            y3 = rotate(p, k, 2).second;
            x4 = rotate(p, l, 3).first;
            y4 = rotate(p, l, 3).second;
            if (checkifsquare(x1, y1, x2, y2, x3, y3, x4, y4)) {
              if (i + j + k + l < min || min == -1) {
                min = i + j + k + l;
              }
            }
          }
        }
      }
    }
    cout << min << endl;
  }
}
