#include <bits/stdc++.h>
using namespace std;
struct point {
  int x, y;
};
point rotate0(point P) {
  point R;
  R.x = -P.y;
  R.y = P.x;
  return R;
}
point rotate(point Base, point Center) {
  point R;
  Base.x -= Center.x;
  Base.y -= Center.y;
  R = rotate0(Base);
  R.x += Center.x;
  R.y += Center.y;
  return R;
}
long long s(int a) {
  long long r;
  r = a * a;
  return r;
}
long long dist(point A, point B) { return (s(A.x - B.x) + s(A.y - B.y)); }
bool Square(point A, point B, point C, point D) {
  std::vector<long long> v;
  v.push_back(dist(A, B));
  v.push_back(dist(C, B));
  v.push_back(dist(D, B));
  v.push_back(dist(A, C));
  v.push_back(dist(A, D));
  v.push_back(dist(C, D));
  sort(v.begin(), v.end());
  if (v[5] == v[4]) {
    if (v[0] == v[1]) {
      if (v[2] == v[3]) {
        if (v[1] == v[2]) {
          if (v[1] != v[5]) {
            return true;
          }
        }
      }
    }
  }
  return false;
}
int addbit(int b) {
  int r;
  for (int i = 0; i <= log2(b); i += 1) {
    r += (b >> i) & 1;
  }
  return r;
}
int N, x, y;
std::vector<point> P, B;
point M;
int main(int argc, char const* argv[]) {
  cin >> N;
  for (int k = 0; k < N; k += 1) {
    P.clear();
    B.clear();
    for (int j = 0; j < 4; j += 1) {
      cin >> x >> y;
      M.x = x;
      M.y = y;
      P.push_back(M);
      cin >> x >> y;
      M.x = x;
      M.y = y;
      B.push_back(M);
    }
    int ans = 10000;
    for (int i = 0; i < 1 << 8; i += 1) {
      int a, b, c, d;
      point Q = P[0], R = P[1], S = P[2], T = P[3];
      a = i % 4;
      b = (i >> 2) % 4;
      c = (i >> 4) % 4;
      d = (i >> 6) % 4;
      for (int j = 0; j < a; j += 1) {
        Q = rotate(Q, B[0]);
      }
      for (int j = 0; j < b; j += 1) {
        R = rotate(R, B[1]);
      }
      for (int j = 0; j < c; j += 1) {
        S = rotate(S, B[2]);
      }
      for (int j = 0; j < d; j += 1) {
        T = rotate(T, B[3]);
      }
      if (Square(Q, R, S, T))
        if (ans > (a + b + c + d)) {
          ans = (a + b + c + d);
        }
    }
    if (ans == 10000) ans = -1;
    cout << ans << '\n';
  }
  return 0;
}
