#include <bits/stdc++.h>
using namespace std;
long long int x[4], y[4], a[4], b[4];
bool check() {
  long long int a = pow((x[0] - x[1]), 2) + pow((y[0] - y[1]), 2);
  long long int b = pow((x[0] - x[2]), 2) + pow((y[0] - y[2]), 2);
  long long int c = pow((x[2] - x[1]), 2) + pow((y[2] - y[1]), 2);
  long long int d = pow((x[0] - x[3]), 2) + pow((y[0] - y[3]), 2);
  long long int e = pow((x[2] - x[3]), 2) + pow((y[2] - y[3]), 2);
  long long int f = pow((x[1] - x[3]), 2) + pow((y[1] - y[3]), 2);
  if (a == 0 || b == 0 || c == 0 || d == 0 || e == 0 || f == 0) return false;
  map<long long int, long long int> m;
  if (a + b == c || a + c == b || b + c == a) {
    if (e + f == c || f + c == e || e + c == f) {
      if (e + d == b || e + b == d || d + b == e) {
        m[a]++;
        m[b]++;
        m[c]++;
        m[d]++;
        m[e]++;
        m[f]++;
        if (m.size() == 2) return true;
      }
    }
  }
  return false;
}
pair<long long int, long long int> rotate(long long int xa, long long int yb,
                                          long long int ax, long long int by) {
  xa -= ax;
  yb -= by;
  long long int xnew = -yb + ax;
  long long int ynew = xa + by;
  return make_pair(xnew, ynew);
}
void solve() {
  for (__typeof(4) i = 0; i < 4; i++) cin >> x[i] >> y[i] >> a[i] >> b[i];
  pair<long long int, long long int> p;
  int a1 = 0, b1 = 0, c = 0, d = 0;
  for (__typeof(4) i = 0; i < 4; i++) {
    b1 = 0;
    for (__typeof(4) j = 0; j < 4; j++) {
      c = 0;
      for (__typeof(4) k = 0; k < 4; k++) {
        d = 0;
        for (__typeof(4) l = 0; l < 4; l++) {
          if (check()) {
            cout << a1 + b1 + c + d << endl;
            return;
          }
          d++;
          p = rotate(x[3], y[3], a[3], b[3]);
          x[3] = p.first;
          y[3] = p.second;
        }
        c++;
        p = rotate(x[2], y[2], a[2], b[2]);
        x[2] = p.first;
        y[2] = p.second;
      }
      b1++;
      p = rotate(x[1], y[1], a[1], b[1]);
      x[1] = p.first;
      y[1] = p.second;
    }
    a1++;
    p = rotate(x[0], y[0], a[0], b[0]);
    x[0] = p.first;
    y[0] = p.second;
  }
  cout << -1 << endl;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t;
  cin >> t;
  while (t--) solve();
  return 0;
}
