#include <bits/stdc++.h>
using namespace std;
const int maxn = 100010;
const int mod = 1e9 + 7;
const double eps = 1e-8;
struct P {
  double x, y;
} p[4][4], O[4];
double d[10];
double dis(int i, int j, int z, int k) {
  return (p[i][j].x - p[z][k].x) * (p[i][j].x - p[z][k].x) +
         (p[i][j].y - p[z][k].y) * (p[i][j].y - p[z][k].y);
}
bool f(double a, double b) { return fabs(a - b) < eps; }
bool check(int i, int j, int z, int k) {
  d[0] = dis(0, i, 1, j);
  d[1] = dis(0, i, 2, z);
  d[2] = dis(0, i, 3, k);
  d[3] = dis(1, j, 2, z);
  d[4] = dis(1, j, 3, k);
  d[5] = dis(2, z, 3, k);
  sort(d, d + 6);
  if (d[0] > eps && f(d[0], d[1]) && f(d[1], d[2]) && f(d[2], d[3]) &&
      f(d[4], d[5]) && f(d[4], 2 * d[0]))
    return true;
  return false;
}
int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j < 4; j++) {
      cin >> p[j][0].x >> p[j][0].y >> O[j].x >> O[j].y;
      double x0 = O[j].x, y0 = O[j].y;
      p[j][2].x = 2 * x0 - p[j][0].x, p[j][2].y = 2 * y0 - p[j][0].y;
      p[j][1].x = x0 + y0 - p[j][0].y, p[j][1].y = y0 - x0 + p[j][0].x;
      p[j][3].x = 2 * x0 - p[j][1].x, p[j][3].y = 2 * y0 - p[j][1].y;
    }
    int ans = 1 << 30;
    for (int i = 0; i <= 3; i++)
      for (int j = 0; j <= 3; j++)
        for (int z = 0; z <= 3; z++)
          for (int k = 0; k <= 3; k++)
            if (check(i, j, z, k) == true) {
              ans = min(ans, i + j + z + k);
            }
    if (ans == (1 << 30))
      cout << -1 << endl;
    else
      cout << ans << endl;
  }
}
