#include <bits/stdc++.h>
using namespace std;
int x[4], y[4], a[4], b[4];
int p[4][4][2];
vector<int> X, Y;
int dis(int x1, int y1, int x2, int y2) {
  return (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2);
}
int dot(int x1, int y1, int x2, int y2, int x3, int y3) {
  return (x1 - x3) * (x2 - x3) + (y1 - y3) * (y2 - y3);
}
void solve() {
  for (int i = 0; i < 4; i++) scanf("%d%d%d%d", &x[i], &y[i], &a[i], &b[i]);
  for (int i = 0; i < 4; i++) {
    p[i][0][0] = x[i];
    p[i][0][1] = y[i];
    for (int j = 1; j < 4; j++) {
      int x = p[i][j - 1][0] - a[i];
      int y = p[i][j - 1][1] - b[i];
      p[i][j][0] = -y + a[i];
      p[i][j][1] = x + b[i];
    }
  }
  int Ans = 10000;
  for (int i = 0; i < 4; i++) {
    for (int j = 0; j < 4; j++) {
      for (int k = 0; k < 4; k++) {
        for (int t = 0; t < 4; t++) {
          X.clear(), Y.clear();
          X.push_back(p[0][i][0]);
          X.push_back(p[1][j][0]);
          X.push_back(p[2][k][0]);
          X.push_back(p[3][t][0]);
          Y.push_back(p[0][i][1]);
          Y.push_back(p[1][j][1]);
          Y.push_back(p[2][k][1]);
          Y.push_back(p[3][t][1]);
          vector<int> tmp;
          for (int ii = 0; ii < 4; ii++) tmp.push_back(ii);
          int flag = 0;
          do {
            int dis1 = dis(X[tmp[0]], Y[tmp[0]], X[tmp[1]], Y[tmp[1]]);
            int dis2 = dis(X[tmp[1]], Y[tmp[1]], X[tmp[2]], Y[tmp[2]]);
            int dis3 = dis(X[tmp[2]], Y[tmp[2]], X[tmp[3]], Y[tmp[3]]);
            int dis4 = dis(X[tmp[3]], Y[tmp[3]], X[tmp[0]], Y[tmp[0]]);
            int dot1 = dot(X[tmp[0]], Y[tmp[0]], X[tmp[2]], Y[tmp[2]],
                           X[tmp[1]], Y[tmp[1]]);
            int dot2 = dot(X[tmp[1]], Y[tmp[1]], X[tmp[3]], Y[tmp[3]],
                           X[tmp[2]], Y[tmp[2]]);
            int dot3 = dot(X[tmp[2]], Y[tmp[2]], X[tmp[0]], Y[tmp[0]],
                           X[tmp[3]], Y[tmp[3]]);
            int dot4 = dot(X[tmp[3]], Y[tmp[3]], X[tmp[1]], Y[tmp[1]],
                           X[tmp[0]], Y[tmp[0]]);
            if (dis1 > 0 && dis1 == dis2 && dis2 == dis3 && dis3 == dis4 &&
                dot1 == 0 && dot2 == 0 && dot3 == 0 && dot4 == 0)
              flag = 1;
          } while (next_permutation(tmp.begin(), tmp.end()));
          if (flag) Ans = min(Ans, i + j + k + t);
        }
      }
    }
  }
  if (Ans == 10000)
    cout << "-1" << endl;
  else
    cout << Ans << endl;
}
int main() {
  int t;
  scanf("%d", &t);
  while (t--) solve();
  return 0;
}
