#include <bits/stdc++.h>
using namespace std;
complex<long double> homes[4];
complex<long double> moles[4];
complex<long double> rotation(complex<long double> P, complex<long double> C,
                              int count) {
  if (count == 0) return P;
  complex<long double> p1 = {C.real() - P.imag() + C.imag(),
                             C.imag() + P.real() - C.real()};
  return rotation(p1, C, count - 1);
}
long double distSq(complex<long double> A, complex<long double> B) {
  return (B.real() - A.real()) * (B.real() - A.real()) +
         (B.imag() - A.imag()) * (B.imag() - A.imag());
}
bool issqr(complex<long double> a, complex<long double> b,
           complex<long double> c, complex<long double> d) {
  long double d2 = distSq(a, b);
  long double d3 = distSq(a, c);
  long double d4 = distSq(a, d);
  if (d2 == 0 || d3 == 0 || d4 == 0) return false;
  if (d2 == d3 && 2 * d2 == d4 && 2 * distSq(b, d) == distSq(b, c)) return true;
  if (d2 == d4 && 2 * d2 == d3 && 2 * distSq(b, c) == distSq(b, d)) return true;
  if (d3 == d4 && 2 * d3 == d2 && 2 * distSq(b, c) == distSq(c, d)) return true;
  return false;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int TC;
  cin >> TC;
  while (TC--) {
    for (int i = 0; i < 4; i++) {
      long double a, b, c, d;
      cin >> a >> b >> c >> d;
      moles[i] = {a, b};
      homes[i] = {c, d};
    }
    int moves = INT_MAX;
    for (int ai = 0; ai < 4; ai++) {
      for (int bi = 0; bi < 4; bi++) {
        for (int ci = 0; ci < 4; ci++) {
          for (int di = 0; di < 4; di++) {
            complex<long double> A = rotation(moles[0], homes[0], ai);
            complex<long double> B = rotation(moles[1], homes[1], bi);
            complex<long double> C = rotation(moles[2], homes[2], ci);
            complex<long double> D = rotation(moles[3], homes[3], di);
            if (issqr(A, B, C, D)) moves = min(moves, ai + bi + ci + di);
          }
        }
      }
    }
    cout << (moves == INT_MAX ? -1 : moves) << "\n";
  }
}
