#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 (x[i] - x[j]) * (x[i] - x[j]) + (y[i] - y[j]) * (y[i] - y[j]);
}
int main() {
  int n, i, j, a, b, u, v, r, t;
  long long D;
  cin >> n;
  while (n--) {
    for (i = 0; i < 4; ++i) {
      scanf("%d%d%d%d", &a, &b, &u, &v);
      a -= u, b -= v;
      x[i * 4] = a, y[i * 4] = b;
      for (j = 1; j < 4; ++j)
        x[i * 4 + j] = -y[i * 4 + j - 1], y[i * 4 + j] = x[i * 4 + j - 1];
      for (j = 0; j < 4; ++j) x[i * 4 + j] += u, y[i * 4 + j] += v;
    }
    int ret = 15;
    for (i = 0; i < 4; ++i)
      for (j = 4; j < 8; ++j)
        for (a = 8; a < 12; ++a)
          for (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] != 0)
              ret = min(ret, i + j + a + b - 24);
          }
    if (ret == 15) ret = -1;
    cout << ret << endl;
  }
}
