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>
#pragma comment(linker, "/STACK:60777216")
using namespace std;
inline string sbstr(string s, int i, int j) { return s.substr(i, j - i + 1); }
const double EPS = 1e-9;
const int IINF = 1000000000;
const double PI = acos(-1.0);
const long long LINF = 6000000000000000000LL;
struct Point {
  int x;
  int y;
  Point() : x(0), y(0) {}
  Point(int _x, int _y) : x(_x), y(_y) {}
  void rotate_90() {
    int x_new = -y;
    int y_new = x;
    x = x_new;
    y = y_new;
  }
  Point operator+(const Point& rhs) { return Point(x + rhs.x, y + rhs.y); }
  Point operator-(const Point& rhs) { return Point(x - rhs.x, y - rhs.y); }
  void rotate(int num) {
    for (int i = 0; i < num; ++i) {
      rotate_90();
    }
  }
  int operator*(const Point& rhs) {
    int ans = x * rhs.x + y * rhs.y;
    return ans;
  }
  void Read() { scanf("%d%d", &x, &y); }
};
double dist(Point a, Point b) {
  double X1 = a.x, Y1 = a.y;
  double X2 = b.x, Y2 = b.y;
  double d1 = X2 - X1;
  d1 *= d1;
  double d2 = Y2 - Y1;
  d2 *= d2;
  return sqrt(d1 + d2);
}
bool is_it(Point X1, Point X2, Point X3, Point X4) {
  double d1 = dist(X1, X2), d2 = dist(X2, X3), d3 = dist(X3, X4),
         d4 = dist(X4, X1), dg1 = dist(X1, X3), dg2 = dist(X2, X4);
  if (fabs(d1 - d2) <= EPS && fabs(d2 - d3) <= EPS && fabs(d3 - d4) <= EPS &&
      fabs(d4 - d1) <= EPS && fabs(dg1 - dg2) <= EPS &&
      fabs(dg1 - hypot(d1, d2)) <= EPS && d1 > EPS) {
    Point r1 = X1 - X2, r2 = X3 - X2;
    Point w1 = X1 - X4, w2 = X3 - X4;
    if (r1 * r2 == 0 && w1 * w2 == 0) {
      return true;
    } else {
      return false;
    }
  }
  return false;
}
bool is_square(Point X1, Point X2, Point X3, Point X4) {
  bool ok = false;
  vector<Point> v;
  v.push_back(X1);
  v.push_back(X2);
  v.push_back(X3);
  v.push_back(X4);
  vector<int> idx;
  for (int i = 0; i < 4; ++i) {
    idx.push_back(i);
  }
  do {
    if (is_it(v[idx[0]], v[idx[1]], v[idx[2]], v[idx[3]])) {
      ok = true;
      break;
    }
  } while (next_permutation(idx.begin(), idx.end()));
  return ok;
}
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    int ans = IINF;
    Point a1, b1;
    b1.Read(), a1.Read();
    Point a2, b2;
    b2.Read(), a2.Read();
    Point a3, b3;
    b3.Read(), a3.Read();
    Point a4, b4;
    b4.Read(), a4.Read();
    for (int k1 = 0; k1 < 4; ++k1) {
      for (int k2 = 0; k2 < 4; ++k2) {
        for (int k3 = 0; k3 < 4; ++k3) {
          for (int k4 = 0; k4 < 4; ++k4) {
            Point v1 = b1 - a1, v2 = b2 - a2, v3 = b3 - a3, v4 = b4 - a4;
            v1.rotate(k1), v2.rotate(k2), v3.rotate(k3), v4.rotate(k4);
            if (is_square(a1 + v1, a2 + v2, a3 + v3, a4 + v4)) {
              ans = min(ans, k1 + k2 + k3 + k4);
            }
          }
        }
      }
    }
    if (ans < IINF) {
      printf("%d\n", ans);
    } else {
      printf("-1\n");
    }
  }
  return 0;
}
