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>
const double Pi = 3.14159265;
const int N = 1e5 + 10;
const unsigned long long base = 163;
const int INF = 0x3f3f3f3f;
const int mod = 1e9 + 7;
const double eps = 1e-5;
const double pi = acos(-1);
using namespace std;
int sign(double k) {
  if (k > eps)
    return 1;
  else if (k < -eps)
    return -1;
  return 0;
}
int cmp(double k1, double k2) { return sign(k1 - k2); }
int inmid(double k1, double k2, double k3) {
  return sign(k1 - k3) * sign(k2 - k3) <= 0;
}
struct point {
  double x, y;
  point(double x = 0, double y = 0) : x(x), y(y) {}
  point operator+(const point &k1) const { return (point){k1.x + x, k1.y + y}; }
  point operator-(const point &k1) const { return (point){x - k1.x, y - k1.y}; }
  point operator*(double k1) const { return (point){x * k1, y * k1}; }
  point operator/(double k1) const { return (point){x / k1, y / k1}; }
  int operator==(const point &k1) const {
    return cmp(x, k1.x) == 0 && cmp(y, k1.y) == 0;
  }
  point turn(double k1) {
    return (point){x * cos(k1) - y * sin(k1), x * sin(k1) + y * cos(k1)};
  }
  point turn90(point b) {
    point vec = (point){x - b.x, y - b.y};
    vec = (point){-vec.y, vec.x};
    return vec + b;
  }
  bool operator<(const point k1) const {
    int a = cmp(x, k1.x);
    if (a == -1)
      return 1;
    else if (a == 1)
      return 0;
    else
      return cmp(y, k1.y) == -1;
  }
  double abs() { return sqrt(x * x + y * y); }
  double abs2() { return x * x + y * y; }
  double dis(point k1) { return ((*this) - k1).abs(); }
  point unit() {
    double w = abs();
    return (point){x / w, y / w};
  }
  void scan() {
    double k1, k2;
    scanf("%lf%lf", &k1, &k2);
    x = k1;
    y = k2;
  }
  void print() { printf("%.11lf %.11lf", x, y); }
  double getw() { return atan2(y, x); }
  point getdel() {
    if (sign(x) == -1 || (sign(x) == 0 && sign(y) == -1))
      return (*this) * (-1);
    else
      return (*this);
  }
  int getP() const { return sign(y) == 1 || (sign(y) == 0 && sign(x) == -1); }
};
int inmid(point k1, point k2, point k3) {
  return inmid(k1.x, k2.x, k3.x) && inmid(k1.y, k2.y, k3.y);
}
double cross(point k1, point k2) { return k1.x * k2.y - k1.y * k2.x; }
double dot(point k1, point k2) { return k1.x * k2.x + k1.y * k2.y; }
double rad(point k1, point k2) { return atan2(cross(k1, k2), dot(k1, k2)); }
vector<point> ConvexHull(vector<point> A, int flag = 1) {
  int n = A.size();
  vector<point> ans(n * 2);
  sort(A.begin(), A.end());
  int now = -1;
  for (int i = 0; i < A.size(); i++) {
    while (now > 0 &&
           sign(cross(ans[now] - ans[now - 1], A[i] - ans[now - 1])) < flag)
      now--;
    ans[++now] = A[i];
  }
  int pre = now;
  for (int i = n - 2; i >= 0; i--) {
    while (now > pre &&
           sign(cross(ans[now] - ans[now - 1], A[i] - ans[now - 1])) < flag)
      now--;
    ans[++now] = A[i];
  }
  ans.resize(now);
  return ans;
}
point a[5], b[5];
bool check() {
  vector<point> vec;
  for (int i = 1; i <= 4; ++i) vec.push_back(a[i]);
  vec = ConvexHull(vec);
  if (vec.size() != 4) return 0;
  vec.push_back(vec[0]);
  double dis = vec[0].dis(vec[1]);
  for (int i = 1; i < 4; ++i) {
    if (sign(dis - vec[i].dis(vec[i + 1])) != 0) return 0;
    if (vec[i + 1].turn90(vec[i]) == vec[i - 1]) {
    } else
      return 0;
  }
  return 1;
}
int main() {
  int T;
  scanf("%d", &T);
  while (T--) {
    int ans = INF;
    for (int i = 1; i <= 4; ++i) a[i].scan(), b[i].scan();
    for (int i = 0; i < 4; ++i) {
      if (i) a[1] = a[1].turn90(b[1]);
      for (int j = 0; j < 4; ++j) {
        if (j) a[2] = a[2].turn90(b[2]);
        for (int k = 0; k < 4; ++k) {
          if (k) a[3] = a[3].turn90(b[3]);
          for (int l = 0; l < 4; ++l) {
            if (l) a[4] = a[4].turn90(b[4]);
            if (check()) {
              ans = min(ans, i + j + k + l);
            }
          }
          a[4] = a[4].turn90(b[4]);
        }
        a[3] = a[3].turn90(b[3]);
      }
      a[2] = a[2].turn90(b[2]);
    }
    if (ans == INF) ans = -1;
    cout << ans << endl;
  }
}
