#include <bits/stdc++.h>
using namespace std;
struct point {
  long long x, y, a, b;
} p[100];
struct may {
  long long x[5];
  long long y[5];
} m[500];
void calcmay(int i, int a, int b) {
  m[i].x[0] = p[i].x;
  m[i].y[0] = p[i].y;
  m[i].x[1] = a + b - p[i].y;
  m[i].y[1] = b + p[i].x - a;
  m[i].x[2] = 2 * a - p[i].x;
  m[i].y[2] = 2 * b - p[i].y;
  m[i].x[3] = a + p[i].y - b;
  m[i].y[3] = a + b - p[i].x;
}
int pand() {
  int w[4];
  memset(w, 0, sizeof(w));
  int u, v;
  for (w[0] = 0; w[0] < 4; w[0]++)
    for (w[1] = 0; w[1] < 4; w[1]++)
      for (w[2] = 0; w[2] < 4; w[2]++)
        for (w[3] = 0; w[3] < 4; w[3]++) {
          long long len[10];
          int wk = 0;
          for (u = 0; u < 4; u++)
            for (v = u + 1; v < 4; v++) {
              len[wk++] =
                  (m[u].x[w[u]] - m[v].x[w[v]]) *
                      (m[u].x[w[u]] - m[v].x[w[v]]) +
                  (m[u].y[w[u]] - m[v].y[w[v]]) * (m[u].y[w[u]] - m[v].y[w[v]]);
            }
          sort(len, len + 6);
          int cnt = 0;
          if (len[0] == len[1] && len[1] == len[2] && len[1] == len[3] &&
              len[4] == len[5] && len[0] != len[5])
            cnt = 1;
          if (cnt == 1) {
            return w[0] + w[1] + w[2] + w[3];
          } else
            continue;
        }
  return -1;
}
int main() {
  int n;
  int t;
  scanf("%d", &t);
  while (t--) {
    int i;
    for (i = 0; i < 4; i++) {
      scanf("%lld%lld%lld%lld", &p[i].x, &p[i].y, &p[i].a, &p[i].b);
      calcmay(i, p[i].a, p[i].b);
    }
    printf("%d\n", pand());
  }
  return 0;
}
