#include <bits/stdc++.h>
using namespace std;
long long x[16], y[16];
long long d[6];
long long dis(int i, int j) {
  return pow(x[i] - x[j], 2) + pow(y[i] - y[j], 2);
}
int main() {
  long long n, u, v, a, b, ans;
  cin >> n;
  while (n--) {
    for (int i = 0; i < 4; i++) {
      cin >> a >> b >> u >> v;
      a -= u, b -= v;
      x[i * 4] = a, y[i * 4] = b;
      for (int j = 1; j < 4; j++) {
        x[i * 4 + j] = -y[i * 4 + j - 1];
        y[i * 4 + j] = x[i * 4 + j - 1];
      }
      for (int j = 0; j < 4; j++) {
        x[i * 4 + j] += u;
        y[i * 4 + j] += v;
      }
    }
    ans = 15;
    for (int i = 0; i < 4; i++) {
      for (int j = 4; j < 8; j++) {
        for (int a = 8; a < 12; a++) {
          for (int b = 12; b < 16; b++) {
            d[0] = dis(i, j);
            d[1] = dis(i, a);
            d[2] = dis(i, b);
            d[3] = dis(j, a);
            d[4] = dis(j, b);
            d[5] = dis(a, b);
            sort(d, d + 6);
            if (d[0] == d[3] && d[0] * 2 == d[5] && d[5] == d[4] && d[0])
              ans = min((int)ans, i + j + a + b - 24);
          }
        }
      }
    }
    if (ans == 15)
      cout << -1 << endl;
    else
      cout << ans << endl;
  }
}
