#include <bits/stdc++.h>
using namespace std;
struct N {
  double x, y;
} node[5], home[5];
struct NN {
  double x[5], y[5];
} res[5];
long long p[10];
long long dis(int a, int b, int i, int j) {
  return (long long)((res[i].x[a] - res[j].x[b]) * (res[i].x[a] - res[j].x[b]) +
                     (res[i].y[a] - res[j].y[b]) * (res[i].y[a] - res[j].y[b]));
}
int main() {
  int cas;
  cin >> cas;
  int i, j, k, l;
  while (cas--) {
    for (i = 0; i < 4; i++) {
      cin >> node[i].x >> node[i].y >> home[i].x >> home[i].y;
      res[i].x[0] = node[i].x;
      res[i].y[0] = node[i].y;
    }
    for (i = 0; i < 4; i++) {
      res[i].x[1] = home[i].x + home[i].y - node[i].y;
      res[i].y[1] = home[i].y - home[i].x + node[i].x;
      res[i].x[3] = home[i].x - home[i].y + node[i].y;
      res[i].y[3] = home[i].y + home[i].x - node[i].x;
      res[i].x[2] = 2 * home[i].x - node[i].x;
      res[i].y[2] = 2 * home[i].y - node[i].y;
    }
    int min = 12345;
    for (i = 0; i < 4; i++) {
      for (j = 0; j < 4; j++) {
        for (k = 0; k < 4; k++) {
          for (l = 0; l < 4; l++) {
            p[0] = dis(i, j, 0, 1);
            p[1] = dis(j, k, 1, 2);
            p[2] = dis(k, l, 2, 3);
            p[3] = dis(l, i, 3, 0);
            p[4] = dis(i, k, 0, 2);
            p[5] = dis(j, l, 1, 3);
            sort(p, p + 6);
            if (p[0] == p[1] && p[1] == p[2] && p[2] == p[3] && p[4] == p[5] &&
                p[0] * 2 == p[4] && p[4] != 0) {
              int tmin = i + j + k + l;
              if (tmin < min) {
                min = tmin;
              }
            }
          }
        }
      }
    }
    if (min != 12345) {
      cout << min << endl;
    } else
      cout << -1 << endl;
  }
}
