#include <bits/stdc++.h>
using namespace std;
using namespace std;
const int INF = int(1e9) * 2, N = 100, mod = 1e9 + 9;
const long long BIG = 1e17;
struct point {
  int a, b, x, y;
  void read() { cin >> x >> y >> a >> b; }
  void rot() {
    int vx = x - a;
    int vy = y - b;
    int rx = -vy;
    int ry = vx;
    x = a + rx;
    y = b + ry;
  }
  bool operator==(point o) {
    if (a != o.a) return 0;
    if (b != o.b) return 0;
    if (x != o.x) return 0;
    if (y != o.y) return 0;
    return 1;
  }
} a[4], b[4];
long long getdist(point a, point b) {
  long long x = a.x - b.x;
  long long y = a.y - b.y;
  return x * x + y * y;
}
long long dist[7];
bool ok(int ca, int cb, int cc, int cd) {
  b[0] = a[0];
  for (int i = 0; i < ca; i++) b[0].rot();
  b[1] = a[1];
  for (int i = 0; i < cb; i++) b[1].rot();
  b[2] = a[2];
  for (int i = 0; i < cc; i++) b[2].rot();
  b[3] = a[3];
  for (int i = 0; i < cd; i++) b[3].rot();
  for (int i = 0; i < 4; i++)
    for (int j = i + 1; j < 4; j++)
      if (b[i] == b[j]) return 0;
  int k = 0;
  for (int i = 0; i < 4; i++)
    for (int j = i + 1; j < 4; j++) dist[k++] = getdist(b[i], b[j]);
  sort(dist, dist + k);
  return (dist[0] == dist[1] && dist[2] == dist[3] && dist[0] == dist[3] &&
          dist[4] == dist[5] && dist[0] + dist[1] == dist[4]);
}
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 4; j++) a[j].read();
    int ans = INF;
    int c = 0;
    for (int ca = 0; ca < 4; ca++)
      for (int cb = 0; cb < 4; cb++)
        for (int cc = 0; cc < 4; cc++)
          for (int cd = 0; cd < 4; cd++)
            if (ok(ca, cb, cc, cd)) ans = min(ans, ca + cb + cc + cd);
    if (ans == INF) ans = -1;
    cout << ans << endl;
  }
}
