#include <bits/stdc++.h>
int x[4], y[4], a[4], b[4], r, t[4], tx[4], ty[4];
void rotate(int l) {
  int i, j;
  i = a[l] + b[l] - ty[l];
  j = tx[l] + b[l] - a[l];
  tx[l] = i;
  ty[l] = j;
}
int valid() {
  int i, j, m1, m2, vi;
  long long d[3], vecx[3], vecy[3];
  for (i = 0; i < 4; i++) {
    vi = 0;
    for (j = 0; j < 4; j++) {
      if (j == i) continue;
      vecx[vi] = tx[j] - tx[i];
      vecy[vi] = ty[j] - ty[i];
      d[vi] = vecx[vi] * vecx[vi] + vecy[vi] * vecy[vi];
      vi++;
    }
    if (d[0] > d[1] && d[0] > d[2]) {
      m1 = 1;
      m2 = 2;
    } else if (d[1] > d[0] && d[1] > d[2]) {
      m1 = 0;
      m2 = 2;
    } else {
      m1 = 0;
      m2 = 1;
    }
    if (d[m1] != d[m2]) return 0;
    if (d[m1] == 0) return 0;
    if (((vecx[m1] * vecx[m2]) + (vecy[m1] * vecy[m2])) != 0) return 0;
  }
  return 1;
}
void search(int l) {
  int i;
  if (l == 4) {
    if (valid()) {
      int s = t[0] + t[1] + t[2] + t[3];
      if (r == -1 || r > s) r = s;
    }
    return;
  }
  tx[l] = x[l];
  ty[l] = y[l];
  t[l] = 0;
  search(l + 1);
  for (i = 1; i < 4; i++) {
    rotate(l);
    t[l] = i;
    search(l + 1);
  }
}
int main() {
  int n, i;
  scanf("%d", &n);
  while (n--) {
    for (i = 0; i < 4; i++) {
      scanf("%d%d%d%d", x + i, y + i, a + i, b + i);
    }
    r = -1;
    search(0);
    printf("%d\n", r);
  }
  return 0;
}
