#include <bits/stdc++.h>
using namespace std;
struct P {
  long long x, y;
};
P rotate90(P a) {
  P b;
  b.x = -a.y, b.y = a.x;
  return b;
}
P ar[4], br[4], cr[4];
P add(P a, P b) {
  P c;
  c.x = a.x + b.x;
  c.y = a.y + b.y;
  return c;
}
long long dis(P a, P b) {
  return (a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y);
}
int check(P eop[]) {
  long long l[16], tp = 0;
  for (int i = 0; i < 4; i++)
    for (int j = i + 1; j < 4; j++) l[tp++] = dis(eop[i], eop[j]);
  sort(l, l + tp);
  if (l[0] == l[1] && l[1] == l[2] && l[2] == l[3] && l[0] == l[3] && l[0] &&
      l[4] == l[5] && l[0] * 2 == l[4])
    return 1;
  else
    return 0;
}
int main() {
  int n;
  scanf("%d", &n);
  while (n--) {
    for (int i = 0; i < 4; i++) {
      scanf("%I64d%I64d%I64d%I64d", &ar[i].x, &ar[i].y, &br[i].x, &br[i].y);
      cr[i].x = ar[i].x - br[i].x;
      cr[i].y = ar[i].y - br[i].y;
    }
    int ans = 999;
    for (int i = 0; i < 4; i++) {
      for (int j = 0; j < 4; j++) {
        for (int k = 0; k < 4; k++) {
          for (int l = 0; l < 4; l++) {
            P eop[4];
            for (int z = 0; z < 4; z++) eop[z] = cr[z];
            for (int z = 0; z < i; z++) eop[0] = rotate90(eop[0]);
            for (int z = 0; z < j; z++) eop[1] = rotate90(eop[1]);
            for (int z = 0; z < k; z++) eop[2] = rotate90(eop[2]);
            for (int z = 0; z < l; z++) eop[3] = rotate90(eop[3]);
            for (int z = 0; z < 4; z++) eop[z] = add(eop[z], br[z]);
            if (check(eop)) ans = min(ans, i + j + k + l);
          }
        }
      }
    }
    printf("%d\n", ans == 999 ? -1 : ans);
  }
  return 0;
}
