#include <bits/stdc++.h>
using namespace std;
int SQR(int x) { return x * x; }
int dis2(int x[], int y[], int p[], int i, int j) {
  return SQR(x[p[i]] - x[p[j]]) + SQR(y[p[i]] - y[p[j]]);
}
bool Check(int x[], int y[]) {
  int p[4];
  for (int i = 0; i < (4); i++) p[i] = i;
  do {
    int l2 = dis2(x, y, p, 0, 1);
    if (l2 == 0) continue;
    bool flag = true;
    for (int i = 0; i < (4); i++) {
      if (dis2(x, y, p, i, (i + 1) % 4) != l2) {
        flag = false;
        break;
      }
    }
    if (flag) {
      if (dis2(x, y, p, 0, 2) == l2 + l2 && dis2(x, y, p, 1, 3) == l2 + l2) {
        return true;
      }
    }
  } while (next_permutation(p, p + 4));
  return false;
}
int main() {
  int cas;
  cin >> cas;
  while (cas--) {
    int x[4], y[4], a[4], b[4];
    for (int i = 0; i < (4); i++) cin >> x[i] >> y[i] >> a[i] >> b[i];
    int ans = 100;
    for (int i = 0; i < (4); i++) {
      for (int j = 0; j < (4); j++) {
        for (int k = 0; k < (4); k++) {
          for (int t = 0; t < (4); t++) {
            if (Check(x, y)) {
              ans = min(ans, i + j + k + t);
            }
            int dx3 = x[3] - a[3], dy3 = y[3] - b[3];
            x[3] = a[3] - dy3;
            y[3] = b[3] + dx3;
          }
          int dx2 = x[2] - a[2], dy2 = y[2] - b[2];
          x[2] = a[2] - dy2;
          y[2] = b[2] + dx2;
        }
        int dx1 = x[1] - a[1], dy1 = y[1] - b[1];
        x[1] = a[1] - dy1;
        y[1] = b[1] + dx1;
      }
      int dx0 = x[0] - a[0], dy0 = y[0] - b[0];
      x[0] = a[0] - dy0;
      y[0] = b[0] + dx0;
    }
    if (ans == 100) ans = -1;
    cout << ans << endl;
  }
  return 0;
}
