#include <bits/stdc++.h>
using namespace std;
int x[4], y[4];
int h[4][2];
bool flag;
bool check() {
  int dj1 = ((x[0] - x[1]) * (x[1] - x[2]) + (y[0] - y[1]) * (y[1] - y[2]));
  int dj2 = ((x[1] - x[2]) * (x[2] - x[3]) + (y[1] - y[2]) * (y[2] - y[3]));
  int len1 = (x[0] - x[1]) * (x[0] - x[1]) + (y[0] - y[1]) * (y[0] - y[1]);
  int len2 = (x[1] - x[2]) * (x[1] - x[2]) + (y[1] - y[2]) * (y[1] - y[2]);
  int len3 = (x[2] - x[3]) * (x[2] - x[3]) + (y[2] - y[3]) * (y[2] - y[3]);
  if (dj1 == 0 && dj2 == 0 && len1 == len2 && len1 == len3 && len1 != 0 &&
      len2 != 0 && len3 != 0)
    return true;
  dj1 = ((x[0] - x[2]) * (x[1] - x[2]) + (y[0] - y[2]) * (y[1] - y[2]));
  dj2 = ((x[1] - x[2]) * (x[1] - x[3]) + (y[1] - y[2]) * (y[1] - y[3]));
  len1 = (x[0] - x[2]) * (x[0] - x[2]) + (y[0] - y[2]) * (y[0] - y[2]);
  len2 = (x[1] - x[2]) * (x[1] - x[2]) + (y[1] - y[2]) * (y[1] - y[2]);
  len3 = (x[1] - x[3]) * (x[1] - x[3]) + (y[1] - y[3]) * (y[1] - y[3]);
  if (dj1 == 0 && dj2 == 0 && len1 == len2 && len1 == len3 && len1 != 0 &&
      len2 != 0 && len3 != 0)
    return true;
  dj1 = ((x[0] - x[1]) * (x[1] - x[3]) + (y[0] - y[1]) * (y[1] - y[3]));
  dj2 = ((x[1] - x[3]) * (x[2] - x[3]) + (y[1] - y[3]) * (y[2] - y[3]));
  len1 = (x[0] - x[1]) * (x[0] - x[1]) + (y[0] - y[1]) * (y[0] - y[1]);
  len2 = (x[1] - x[3]) * (x[1] - x[3]) + (y[1] - y[3]) * (y[1] - y[3]);
  len3 = (x[2] - x[3]) * (x[2] - x[3]) + (y[2] - y[3]) * (y[2] - y[3]);
  if (dj1 == 0 && dj2 == 0 && len1 == len2 && len1 == len3 && len1 != 0 &&
      len2 != 0 && len3 != 0)
    return true;
  return false;
}
void operate(int dot) {
  int dx = x[dot] - h[dot][0];
  int dy = y[dot] - h[dot][1];
  x[dot] = h[dot][0] - dy;
  y[dot] = h[dot][1] + dx;
}
void aoperate(int dot) {
  int dx = x[dot] - h[dot][0];
  int dy = y[dot] - h[dot][1];
  x[dot] = h[dot][0] + dy;
  y[dot] = h[dot][1] - dx;
}
int main() {
  int n, i, j, k, q;
  scanf("%d", &n);
  while (n--) {
    for (i = 0; i <= 3; i++) {
      scanf("%d %d %d %d", &x[i], &y[i], &h[i][0], &h[i][1]);
    }
    flag = false;
    for (i = 0; i <= 3; i++) {
      int ii = i;
      while (ii--) operate(0);
      for (j = 0; j <= 3; j++) {
        int jj = j;
        while (jj--) operate(1);
        for (k = 0; k <= 3; k++) {
          int kk = k;
          while (kk--) operate(2);
          for (q = 0; q <= 3; q++) {
            int qq = q;
            while (qq--) operate(3);
            if (check()) {
              printf("%d\n", i + j + k + q);
              flag = true;
              break;
            }
            if (flag) break;
            qq = q;
            while (qq--) aoperate(3);
          }
          if (flag) break;
          kk = k;
          while (kk--) aoperate(2);
        }
        if (flag) break;
        jj = j;
        while (jj--) aoperate(1);
      }
      if (flag) break;
      ii = i;
      while (ii--) aoperate(0);
    }
    if (!flag) printf("-1\n");
  }
  return 0;
}
