#include <bits/stdc++.h>
using namespace std;
struct point {
  long long x, y;
};
long long c1 = 0;
long long dist(point a, point b) {
  return (a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y);
}
long long check(point a, point b, point c, point d) {
  vector<long long> v;
  v.push_back(dist(a, b));
  v.push_back(dist(a, c));
  v.push_back(dist(a, d));
  v.push_back(dist(b, c));
  v.push_back(dist(b, d));
  v.push_back(dist(c, d));
  sort(v.begin(), v.end());
  long long dist = 0;
  for (long long i = 0; i < 6;) {
    long long ind = i;
    dist++;
    long long count = 0;
    while (ind < 6 && v[ind] == v[i]) {
      i++;
    }
  }
  if (dist != 2) return 0;
  long long ind = 0;
  if (v[3] != v[5] && v[4] == v[5]) return 1;
  return 0;
}
point p[5][5];
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  long long n;
  cin >> n;
  while (n--) {
    for (long long i = 0; i < 4; i++) {
      long long x1, y1, a1, b1;
      cin >> x1 >> y1 >> a1 >> b1;
      p[i][0].x = x1;
      p[i][0].y = y1;
      long long diffx = x1 - a1;
      long long diffy = y1 - b1;
      for (long long j = 1; j < 4; j++) {
        p[i][j].x = a1;
        p[i][j].y = b1;
        swap(diffx, diffy);
        diffx *= -1;
        p[i][j].x += diffx;
        p[i][j].y += diffy;
      }
    }
    long long ans = 100;
    for (long long i = 0; i < 4; i++) {
      for (long long j = 0; j < 4; j++) {
        for (long long l = 0; l < 4; l++) {
          for (long long k = 0; k < 4; k++) {
            if (check(p[0][i], p[1][j], p[2][k], p[3][l]))
              ans = min(ans, i + j + k + l);
          }
        }
      }
    }
    if (ans != 100)
      cout << ans << '\n';
    else
      cout << -1 << '\n';
  }
  return 0;
}
