#include <bits/stdc++.h>
using namespace std;
struct PT {
  double x, y;
  PT() {}
  PT(double x, double y) : x(x), y(y) {}
  PT(const PT &p) : x(p.x), y(p.y) {}
  PT operator-(const PT &p) { return PT(x - p.x, y - p.y); }
  PT operator+(const PT &p) { return PT(x + p.x, y + p.y); }
  PT operator*(double c) { return PT(x * c, y * c); }
  PT operator/(double c) { return PT(x / c, y / c); }
};
double dot(PT p, PT q) { return p.x * q.x + p.y * q.y; }
double dist2(PT p, PT q) { return dot(p - q, p - q); }
double cross(PT p, PT q) { return p.x * q.y - p.y * q.x; }
ostream &operator<<(ostream &os, const PT &p) {
  os << "(" << p.x << "," << p.y << ")";
}
PT RotateCCW90(PT p) { return PT(-p.y, p.x); }
PT RotateCW90(PT p) { return PT(p.y, -p.x); }
PT RotateCCW(PT p, double t) {
  return PT(p.x * cos(t) - p.y * sin(t), p.x * sin(t) + p.y * cos(t));
}
bool rectangle(PT p1, PT p2, PT p3, PT p4) {
  long long d2 = dist2(p1, p2);
  long long d3 = dist2(p1, p3);
  long long d4 = dist2(p1, p4);
  long long d5 = dist2(p2, p3);
  long long d6 = dist2(p2, p4);
  long long d7 = dist2(p3, p4);
  if (d4 == 0 || d2 == 0 || d3 == 0 || d5 == 0 || d6 == 0 || d7 == 0)
    return false;
  if (d2 == d3 && 2 * d2 == d4) {
    long long d = dist2(p2, p4);
    if (d == 0) return false;
    return (d == dist2(p3, p4) && d == d2);
  }
  if (d3 == d4 && 2 * d3 == d2) {
    long long d = dist2(p2, p3);
    if (d == 0) return false;
    return (d == dist2(p2, p4) && d == d3);
  }
  if (d2 == d4 && 2 * d2 == d3) {
    long long d = dist2(p2, p3);
    if (d == 0) return false;
    return (d == dist2(p3, p4) && d == d2);
  }
  return false;
}
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    vector<vector<PT> > v(4);
    int res = 1e8;
    for (int j = 0; j < 4; ++j) {
      int x, y, a, b;
      cin >> x >> y >> a >> b;
      v[j].push_back(PT(x, y));
      PT center = PT(a, b);
      PT curr = PT(x, y) - center;
      PT r1 = RotateCCW90(curr);
      PT r2 = RotateCCW90(r1);
      PT r3 = RotateCCW90(r2);
      v[j].push_back(r1 + center);
      v[j].push_back(r2 + center);
      v[j].push_back(r3 + center);
    }
    for (int j = 0; j < 4; ++j) {
      for (int k = 0; k < 4; ++k) {
        for (int l = 0; l < 4; ++l) {
          for (int m = 0; m < 4; ++m) {
            if (rectangle(v[0][j], v[1][k], v[2][l], v[3][m]))
              res = min(res, j + k + l + m);
          }
        }
      }
    }
    if (res == (int)1e8)
      cout << -1 << '\n';
    else
      cout << res << '\n';
  }
}
