#include <bits/stdc++.h>
using namespace std;
template <class T>
T gcd(T a, T b) {
  T r;
  while (b != 0) {
    r = a % b;
    a = b;
    b = r;
  }
  return a;
}
template <class T>
T lcm(T a, T b) {
  return a / gcd(a, b) * b;
}
template <class T>
int getbit(T s, int i) {
  return (s >> i) & 1;
}
template <class T>
T onbit(T s, int i) {
  return s | (T(1) << i);
}
template <class T>
T offbit(T s, int i) {
  return s & (~(T(1) << i));
}
const double PI = 2 * acos(0.0);
const double eps = 1e-6;
const int infi = 1e9;
const long long Linfi = (long long)1e15;
const long long MOD = 1000000007;
const int c1 = 11;
const int c2 = 37;
int n, k;
int a[10], b[10], c[10], d[10];
pair<int, int> P[5];
pair<int, int> quay(int first, int second, int a, int b, int step) {
  if (step == 0) return pair<int, int>(first, second);
  int dx, dy, X, Y;
  dx = first - a;
  dy = second - b;
  while (step--) {
    X = -dy;
    Y = dx;
    dx = X;
    dy = Y;
  }
  first = X + a;
  second = Y + b;
  return pair<int, int>(first, second);
}
long long dist(pair<int, int> A, pair<int, int> B) {
  long long dx = A.first - B.first, dy = A.second - B.second;
  return dx * dx + dy * dy;
}
double getAngle(pair<int, int> A, pair<int, int> B, pair<int, int> C) {
  double a = sqrt(dist(B, C));
  double b = sqrt(dist(C, A));
  double c = sqrt(dist(A, B));
  double agoc = (b * b + c * c - a * a) / (2 * b * c);
  return acos(agoc);
}
int check() {
  int p[5];
  for (int i = 1; i <= 4; i++) p[i] = i;
  do {
    set<long long> S;
    S.insert(dist(P[p[1]], P[p[4]]));
    for (int i = 2; i <= 4; i++) S.insert(dist(P[p[i]], P[p[i - 1]]));
    if (S.size() > 1) continue;
    double goc1 = getAngle(P[p[1]], P[p[4]], P[p[2]]);
    double goc2 = getAngle(P[p[2]], P[p[1]], P[p[3]]);
    double goc3 = getAngle(P[p[3]], P[p[2]], P[p[4]]);
    double goc4 = getAngle(P[p[4]], P[p[3]], P[p[1]]);
    if (abs(goc1 - PI / 2) < eps && abs(goc2 - PI / 2) < eps &&
        abs(goc3 - PI / 2) < eps && abs(goc4 - PI / 2) < eps)
      return 1;
  } while (next_permutation(p + 1, p + 5));
  return 0;
}
void solve() {
  int ans = infi;
  for (int i = 0; i <= 3; i++)
    for (int j = 0; j <= 3; j++)
      for (int u = 0; u <= 3; u++)
        for (int v = 0; v <= 3; v++) {
          P[1] = quay(a[1], b[1], c[1], d[1], i);
          P[2] = quay(a[2], b[2], c[2], d[2], j);
          P[3] = quay(a[3], b[3], c[3], d[3], u);
          P[4] = quay(a[4], b[4], c[4], d[4], v);
          if (check()) ans = min(ans, i + j + u + v);
        }
  if (ans == infi)
    cout << -1 << endl;
  else
    cout << ans << endl;
}
int main() {
  ios::sync_with_stdio(false);
  int sotest;
  cin >> sotest;
  while (sotest--) {
    for (int i = 1; i <= 4; i++) cin >> a[i] >> b[i] >> c[i] >> d[i];
    solve();
  }
  return 0;
}
