#include <bits/stdc++.h>
#pragma GCC optimize("O2")
using namespace std;
const long long MAX = 1e5 + 5;
const long long MAX2 = 11;
const int MOD = 1000000000 + 7;
const long long INF = 20000;
const int nr[] = {1, 0, -1, 0, 1, 1, -1, -1};
const int nc[] = {0, 1, 0, -1, 1, -1, 1, -1};
int n, ans;
pair<double, double> a[4], b[4], df;
double s, d, ts, td, eps = 1e-9;
bool val;
double dabs(double D) {
  if (D < 0.0) return -D;
  return D;
}
void f(int i) {
  df = {b[i].second - a[i].second, a[i].first - b[i].first};
  a[i] = {b[i].first + df.first, b[i].second + df.second};
}
void cek(int i) {
  double z, r1, r2;
  int cnt = 0;
  z = sqrt((a[i].first - a[(i + 1) % 4].first) *
               (a[i].first - a[(i + 1) % 4].first) +
           (a[i].second - a[(i + 1) % 4].second) *
               (a[i].second - a[(i + 1) % 4].second));
  r1 = r2 = z;
  z = sqrt((a[i].first - a[(i + 2) % 4].first) *
               (a[i].first - a[(i + 2) % 4].first) +
           (a[i].second - a[(i + 2) % 4].second) *
               (a[i].second - a[(i + 2) % 4].second));
  if (r1 > z) r1 = z, cnt++;
  if (r2 < z) r2 = z, cnt++;
  z = sqrt((a[i].first - a[(i + 3) % 4].first) *
               (a[i].first - a[(i + 3) % 4].first) +
           (a[i].second - a[(i + 3) % 4].second) *
               (a[i].second - a[(i + 3) % 4].second));
  if (r1 > z) r1 = z, cnt++;
  if (r2 < z) r2 = z, cnt++;
  ts = r1, td = r2;
  if (cnt > 1) val = 0;
}
int main() {
  cout << fixed << setprecision(6);
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (int tc = 1; tc <= n; tc++) {
    for (int i = 0; i <= 3; i++)
      cin >> a[i].first >> a[i].second >> b[i].first >> b[i].second;
    ans = 16;
    for (int i = 0; i <= 3; i++) {
      for (int j = 0; j <= 3; j++) {
        for (int k = 0; k <= 3; k++) {
          for (int o = 0; o <= 3; o++) {
            cek(0);
            s = ts, d = td;
            if (s > 0.0001)
              val = 1;
            else
              val = 0;
            for (int tes = 1; tes <= 3; tes++) {
              cek(tes);
              if (dabs(s - ts) > eps || dabs(d - td) > eps) val = 0;
            }
            if (val) ans = min(ans, i + j + k + o);
            f(3);
          }
          f(2);
        }
        f(1);
      }
      f(0);
    }
    if (ans == 16)
      cout << -1 << "\n";
    else
      cout << ans << "\n";
  }
  return 0;
}
