#include <bits/stdc++.h>
using namespace std;
bool check(long long* x1, long long* y1) {
  set<pair<long long, long long> > h;
  h.insert(make_pair(x1[0], y1[0]));
  h.insert(make_pair(x1[1], y1[1]));
  h.insert(make_pair(x1[2], y1[2]));
  h.insert(make_pair(x1[3], y1[3]));
  if (h.size() != 4)
    return false;
  else {
    vector<pair<long long, long long> > temp;
    for (int i = 1; i < 4; i++) {
      long long z =
          (x1[0] - x1[i]) * (x1[0] - x1[i]) + (y1[0] - y1[i]) * (y1[0] - y1[i]);
      temp.push_back(make_pair(z, i));
    }
    sort(temp.begin(), temp.end());
    if (temp[0].first != temp[1].first)
      return false;
    else {
      if (temp[2].first != 2ll * temp[1].first)
        return false;
      else {
        long long si = temp[0].first;
        long long si1 = (x1[temp[2].second] - x1[temp[1].second]) *
                            (x1[temp[2].second] - x1[temp[1].second]) +
                        (y1[temp[2].second] - y1[temp[1].second]) *
                            (y1[temp[2].second] - y1[temp[1].second]);
        long long si2 = (x1[temp[2].second] - x1[temp[0].second]) *
                            (x1[temp[2].second] - x1[temp[0].second]) +
                        (y1[temp[2].second] - y1[temp[0].second]) *
                            (y1[temp[2].second] - y1[temp[0].second]);
        if (si == si1 and si == si2)
          return true;
        else
          return false;
      }
    }
  }
}
void myFn(long long& xn, long long& yn, long long xo, long long yo, long long a,
          long long b, int p) {
  if (p == 0) {
    xn = xo;
    yn = yo;
  } else if (p == 1) {
    xn = a + b - yo;
    yn = b + xo - a;
  } else if (p == 2) {
    xn = 2ll * a - xo;
    yn = 2ll * b - yo;
  } else {
    xn = a + yo - b;
    yn = b + a - xo;
  }
}
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    long long x[4], y[4], a[4], b[4];
    for (int j = 0; j < 4; j++) cin >> x[j] >> y[j] >> a[j] >> b[j];
    int m = INT_MAX;
    for (int p = 0; p < 4; p++) {
      for (int q = 0; q < 4; q++) {
        for (int r = 0; r < 4; r++) {
          for (int s = 0; s < 4; s++) {
            long long x1[4], y1[4];
            myFn(x1[0], y1[0], x[0], y[0], a[0], b[0], p);
            myFn(x1[1], y1[1], x[1], y[1], a[1], b[1], q);
            myFn(x1[2], y1[2], x[2], y[2], a[2], b[2], r);
            myFn(x1[3], y1[3], x[3], y[3], a[3], b[3], s);
            int temp = p + q + r + s;
            if (check(x1, y1) and temp < m) m = temp;
          }
        }
      }
    }
    if (m == INT_MAX) m = -1;
    cout << m << endl;
  }
}
