#include <bits/stdc++.h>
using namespace std;
string s, s1, s2, s3;
vector<pair<long long, long long> > v[10];
long long i, j, x, y, xp, yp, u[310][310], d[20], t, n, a, b, dif[300], z[20];
pair<long long, long long> p[10];
long long dis(long long x, long long y) {
  long long r = 0, s = 0;
  r = p[x].second - p[y].second;
  s = r * r;
  r = p[x].first - p[y].first;
  s += (r * r);
  return s;
}
long long check2() {
  z[0] = dis(0, 1);
  z[1] = dis(3, 1);
  z[2] = dis(2, 3);
  z[3] = dis(0, 2);
  z[4] = dis(1, 2);
  z[5] = dis(0, 3);
  sort(z, z + 6);
  long long r = z[0], QQ = true;
  for (long long f = 1; f < 4; f++)
    if (!z[f] && z[f] != r) QQ = false;
  if (z[4] == z[5] && z[5] == 2 * z[3]) return 1;
  return 0;
  if (QQ) {
    r = (p[1].second - p[0].second) * (p[1].second - p[3].second);
    long long f = (p[3].first - p[1].first) * (p[1].first - p[0].first);
    if (r && r == f) return 1;
  }
  return 0;
}
long long check(long long x) {
  long long Q = false;
  for (long long i = 0; i < 4; i++) {
    p[i] = v[i][u[x][i]];
  }
  sort(p, p + 4);
  for (int i = 0; i < 3; i++)
    if (p[i].first == p[i + 1].first && p[i].second == p[i + 1].second)
      return 0;
  if (p[0].first == p[1].first && p[2].first == p[3].first &&
      p[1].first != p[2].first) {
    if (p[0].second == p[2].second && p[1].second == p[3].second &&
        p[1].second != p[0].second) {
      if (dis(0, 1) == dis(1, 3)) Q = true;
    }
  }
  if (Q) return 1;
  Q = check2();
  return Q;
}
int main() {
  x = 0;
  while (x < 256) {
    for (j = 0; j < 4; j++) {
      u[x][j] = d[j];
      dif[x] += u[x][j];
    }
    d[0]++;
    t = 0;
    while (d[t] > 3) {
      d[t] = 0;
      d[t + 1]++;
      t++;
    }
    x++;
  }
  cin >> n;
  for (long long in = 0; in < n; in++) {
    long long mind = INT_MAX;
    for (long long q = 0; q < 4; q++) {
      v[q].clear();
      cin >> x >> y >> a >> b;
      for (j = 0; j < 4; j++) {
        xp = b + a - y;
        yp = x - a + b;
        v[q].push_back(make_pair(x, y));
        x = xp;
        y = yp;
      }
    }
    for (j = 0; j < 256; j++) {
      if (dif[j] < mind && check(j)) {
        mind = dif[j];
      }
    }
    if (mind < 10000)
      cout << mind << endl;
    else
      cout << -1 << endl;
  }
  return 0;
}
