#include <bits/stdc++.h>
using namespace std;
long long n, i, j, ans = (long long)1E9;
long long a[402 + 6][6];
vector<pair<long long, pair<long long, long long> > > v[400090];
vector<long long> perm[345];
map<long long, long long> m1, m2;
bool check(pair<long long, long long> A, pair<long long, long long> B,
           pair<long long, long long> C, pair<long long, long long> D) {
  set<long long> s;
  long long x = (A.first - B.first) * (A.first - B.first) +
                (A.second - B.second) * (A.second - B.second);
  s.insert(x);
  x = (A.first - C.first) * (A.first - C.first) +
      (A.second - C.second) * (A.second - C.second);
  s.insert(x);
  x = (A.first - D.first) * (A.first - D.first) +
      (A.second - D.second) * (A.second - D.second);
  s.insert(x);
  x = (B.first - C.first) * (B.first - C.first) +
      (B.second - C.second) * (B.second - C.second);
  s.insert(x);
  x = (B.first - D.first) * (B.first - D.first) +
      (B.second - D.second) * (B.second - D.second);
  s.insert(x);
  x = (C.first - D.first) * (C.first - D.first) +
      (C.second - D.second) * (C.second - D.second);
  s.insert(x);
  long long y = *s.begin();
  s.erase(s.begin());
  if (y == 0) return false;
  long long z = *s.begin();
  s.erase(s.begin());
  if ((long long)s.size() == 0 and 2 * y == z) return true;
  return false;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n;
  for (i = 1; i <= 4 * n; i++) cin >> a[i][1] >> a[i][2] >> a[i][3] >> a[i][4];
  v[0].push_back({0, {0, 0}});
  m1[90] = 1, m2[90] = 0;
  m1[180] = 0, m2[180] = -1;
  m1[270] = -1, m2[270] = 0;
  for (i = 1; i <= 4 * n; i++) {
    v[i].push_back({0, {a[i][1], a[i][2]}});
    for (j = 1; j <= 3; j++) {
      long long x = m2[j * 90] * (a[i][1] - a[i][3]) -
                    m1[j * 90] * (a[i][2] - a[i][4]) + a[i][3];
      long long y = m1[j * 90] * (a[i][1] - a[i][3]) +
                    m2[j * 90] * (a[i][2] - a[i][4]) + a[i][4];
      v[i].push_back({j, {x, y}});
    }
  }
  long long k = 0;
  for (long long J1 = 0; J1 < 4; J1++) {
    for (long long J2 = 0; J2 < 4; J2++)
      for (long long J3 = 0; J3 < 4; J3++)
        for (long long J4 = 0; J4 < 4; J4++)
          perm[k].push_back(J1), perm[k].push_back(J2), perm[k].push_back(J3),
              perm[k].push_back(J4), k++;
  }
  i = 1;
  while (i <= 4 * n) {
    ans = (long long)1E9;
    for (j = 0; j < 256; j++) {
      long long c = perm[j][0], d = perm[j][1], e = perm[j][2], f = perm[j][3];
      if (check(v[i][c].second, v[i + 1][d].second, v[i + 2][e].second,
                v[i + 3][f].second))
        ans = min(ans, v[i][c].first + v[i + 1][d].first + v[i + 2][e].first +
                           v[i + 3][f].first);
    }
    if (ans == (long long)1E9)
      cout << -1 << endl;
    else
      cout << ans << endl;
    ans = (long long)1E9;
    i += 4;
  }
}
