#include <bits/stdc++.h>
using namespace std;
int x[4], y[4], a[4], b[4];
void rotate(int i) {
  int varx = x[i];
  x[i] = b[i] - y[i] + a[i];
  y[i] = varx + b[i] - a[i];
}
bool check() {
  vector<long long> sides;
  int i, j;
  for (i = 0; i < 4; i++)
    for (j = i + 1; j < 4; j++)
      sides.push_back((x[i] - x[j]) * (x[i] - x[j]) * 1LL +
                      1LL * (y[i] - y[j]) * (y[i] - y[j]));
  sort(sides.begin(), sides.end());
  if (sides[0] == 0) return 0;
  for (i = 0; i < 4; i++)
    if (sides[i] != sides[0]) return 0;
  if (sides[4] != sides[5] || sides[0] * 2 != sides[4]) return 0;
  return 1;
}
int main() {
  int n;
  scanf("%d", &n);
  while (n--) {
    int ans, gl = INT_MAX, i, j, k, l;
    for (i = 0; i < 4; i++) cin >> x[i] >> y[i] >> a[i] >> b[i];
    for (i = 0; i < 4; i++) {
      rotate(0);
      for (j = 0; j < 4; j++) {
        rotate(1);
        for (k = 0; k < 4; k++) {
          rotate(2);
          for (l = 0; l < 4; l++) {
            rotate(3);
            if (check() == 1) {
              ans = (i + 1) % 4 + (j + 1) % 4 + (k + 1) % 4 + (l + 1) % 4;
              gl = min(ans, gl);
            }
          }
        }
      }
    }
    if (gl == INT_MAX)
      cout << -1 << endl;
    else
      cout << gl << endl;
  }
  return 0;
}
