#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) { return (b == 0 ? a : gcd(b, a % b)); }
long long lcm(long long a, long long b) { return (a * (b / gcd(a, b))); }
bool getbit(int num, int idx) { return (num >> idx & 1) == 1; }
int setbit(int num, int idx, bool val) {
  if (val == true) return (num | (1 << idx));
  return num & ~(1 << idx);
}
int flipbit(int num, int idx) { return num ^ (1 << idx); }
int cntbits(int mask) {
  int res = 0;
  while (mask) mask &= (mask - 1), res++;
  return res;
}
int n;
struct point {
 public:
  long double x, y;
  point() { x = y = 0.0; }
  point(double _x, double _y) {
    x = _x;
    y = _y;
  }
  bool operator==(point y1) {
    return fabs(x - y1.x) < 1e-8 && fabs(y - y1.y) < 1e-8;
  }
  bool operator<(point other) const {
    if (fabs(x - other.x) > 1e-8) return x < other.x;
    return y < other.y;
  }
};
vector<pair<point, point> > arr(4);
long double distsq(point p1, point p2) {
  return (p1.x - p2.x) * (p1.x - p2.x) + (p1.y - p2.y) * (p1.y - p2.y);
}
point RotatePoint(point p, point center, double theta) {
  long double s = sin(theta);
  long double c = cos(theta);
  p.x -= center.x;
  p.y -= center.y;
  long double xnew = p.x * c - p.y * s;
  long double ynew = p.x * s + p.y * c;
  p.x = xnew + center.x;
  p.y = ynew + center.y;
  return p;
}
bool isSquare(point p1, point p2, point p3, point p4) {
  long long d2 = round(distsq(p1, p2));
  long long d3 = round(distsq(p1, p3));
  long long d4 = round(distsq(p1, p4));
  if (d2 == d3 && 2 * d2 == d4) {
    long long d = round(distsq(p2, p4));
    return (d == round(distsq(p3, p4)) && d == d2);
  }
  if (d3 == d4 && 2 * d3 == d2) {
    long long d = round(distsq(p2, p3));
    return (d == round(distsq(p2, p4)) && d == d3);
  }
  if (d2 == d4 && 2 * d2 == d3) {
    long long d = round(distsq(p2, p3));
    return (d == round(distsq(p3, p4)) && d == d2);
  }
  return false;
}
int sol(int k, point a, point b, point c, point d) {
  if (k == 4) {
    int call = 4;
    point mat[4] = {a, b, c, d};
    for (int i = 0; i < int(4); ++i)
      for (int j = int(i + 1); j < int(4); ++j)
        if (mat[i] == mat[j]) {
          call--;
          break;
        }
    if (call < 4) return 1e5;
    return isSquare(a, b, c, d) == 1 ? 0 : 1e8;
  }
  int res = 1e8;
  for (int i = 0; i < int(4); ++i) {
    if (k == 0)
      res = min(
          res, i + sol(k + 1, RotatePoint(a, arr[0].second, (acos(-1) / 2) * i),
                       b, c, d));
    else if (k == 1)
      res = min(res, i + sol(k + 1, a,
                             RotatePoint(b, arr[1].second, (acos(-1) / 2) * i),
                             c, d));
    else if (k == 2)
      res = min(res,
                i + sol(k + 1, a, b,
                        RotatePoint(c, arr[2].second, (acos(-1) / 2) * i), d));
    else if (k == 3)
      res =
          min(res, i + sol(k + 1, a, b, c,
                           RotatePoint(d, arr[3].second, (acos(-1) / 2) * i)));
  }
  return res;
}
int main() {
  cin >> n;
  for (int i = 0; i < int(n); ++i) {
    for (int j = 0; j < int(4); ++j)
      cin >> arr[j].first.x >> arr[j].first.y >> arr[j].second.x >>
          arr[j].second.y;
    int res = sol(0, arr[0].first, arr[1].first, arr[2].first, arr[3].first);
    cout << (res < 1000 ? res : -1) << endl;
  }
  return 0;
}
