#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:100000000000,100000000000")
using namespace std;
const double eps = 1E-9;
const double Exp = 2.718281828459045;
const double Pi = 3.1415926535897932;
const int NMAX = 100000 + 5;
const int MMAX = 100000 + 5;
const int INF = 1000000000;
const int BASE = 1000000007;
template <typename T>
inline T abs(const T a) {
  if (a < 0) return -a;
  return a;
}
template <typename T>
inline T sqr(const T &a) {
  return a * a;
}
void rot(pair<int, int> &a, pair<int, int> &b) {
  pair<int, int> buf = a;
  a.first = (b.first + b.second - buf.second);
  a.second = (b.second - b.first + buf.first);
}
long long dist(const pair<int, int> &a, const pair<int, int> &b) {
  return (a.first - b.first) * 1ll * (a.first - b.first) +
         (a.second - b.second) * 1ll * (a.second - b.second);
}
bool check(const pair<int, int> &a, const pair<int, int> &b,
           const pair<int, int> &c, const pair<int, int> &d) {
  long long di[6];
  di[0] = dist(a, b);
  di[1] = dist(a, c);
  di[2] = dist(a, d);
  di[3] = dist(b, c);
  di[4] = dist(b, d);
  di[5] = dist(c, d);
  sort(di, di + 6);
  if (di[0] == di[1] && di[1] == di[2] && di[2] == di[3] &&
      di[4] == 2 * di[0] && di[5] == 2 * di[0] && di[0] > 0)
    return true;
  return false;
}
int main() {
  ios::sync_with_stdio(false);
  int n, i, j;
  int j1, j2, j3, j4;
  cin >> n;
  pair<int, int> k[NMAX];
  pair<int, int> d[NMAX];
  int ans;
  for (i = 1; i <= n; i++) {
    for (j = 1; j <= 4; j++) {
      cin >> k[j].first >> k[j].second >> d[j].first >> d[j].second;
    }
    ans = INF;
    for (j1 = 0; j1 < 4; j1++) {
      for (j2 = 0; j2 < 4; j2++) {
        for (j3 = 0; j3 < 4; j3++) {
          for (j4 = 0; j4 < 4; j4++) {
            if (check(k[1], k[2], k[3], k[4])) {
              ans = min(ans, j1 + j2 + j3 + j4);
            }
            rot(k[4], d[4]);
          }
          rot(k[3], d[3]);
        }
        rot(k[2], d[2]);
      }
      rot(k[1], d[1]);
    }
    if (ans == INF)
      cout << -1 << endl;
    else
      cout << ans << endl;
  }
  return 0;
}
