#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1.0);
const double eps = 1e-8;
pair<long long, long long> rotat(pair<long long, long long> A,
                                 pair<long long, long long> H) {
  long long xx = A.first, yy = A.second;
  long long aa = H.first, bb = H.second;
  int ret1, ret2;
  ret1 = aa - (yy - bb);
  ret2 = bb + (xx - aa);
  return pair<long long, long long>(ret1, ret2);
}
long long leng(pair<long long, long long> a, pair<long long, long long> b) {
  return (a.first - b.first) * (a.first - b.first) +
         (a.second - b.second) * (a.second - b.second);
}
pair<long long, long long> add(pair<long long, long long> a,
                               pair<long long, long long> b) {
  return make_pair(a.first + b.first, a.second + b.second);
}
pair<long long, long long> sub(pair<long long, long long> a,
                               pair<long long, long long> b) {
  return make_pair(a.first - b.first, a.second - b.second);
}
bool cool_this(vector<pair<long long, long long> > curr) {
  assert(((int)(curr.size())) == 4);
  vector<long long> D;
  for (int i = 0; i <= 2; i++) D.push_back(leng(curr[i], curr[i + 1]));
  D.push_back(leng(curr[0], curr[3]));
  sort(D.begin(), D.end());
  if (D[0] == 0) return false;
  long long hy = leng(curr[0], curr[2]);
  if (hy != 2LL * D[0]) return false;
  return (D[0] == D[3]);
}
bool cool(vector<pair<long long, long long> > in) {
  sort(in.begin(), in.end());
  for (int i = 0; i < 4; i++)
    for (int j = i + 1; j < 4; j++)
      if (in[i] == in[j]) return false;
  do {
    if (cool_this(in)) return true;
  } while (next_permutation(in.begin(), in.end()));
  return false;
}
void trace(vector<pair<long long, long long> > in) {
  for (int i = 0; i < ((int)(in.size())); i++)
    cout << in[i].first << "  " << in[i].second << endl;
  cout << "\n\n\n";
}
int solve() {
  vector<pair<long long, long long> > curr(4), home(4), save;
  for (int i = 0; i < 4; i++) {
    cin >> curr[i].first >> curr[i].second >> home[i].first >> home[i].second;
  }
  save = curr;
  int ans = -1;
  int a = 0, b = 0, c = 0, d = 0;
  for (a = 0; a < 4; a++, curr[0] = rotat(curr[0], home[0])) {
    for (b = 0; b < 4; b++, curr[1] = rotat(curr[1], home[1])) {
      if (b == 0) curr[1] = save[1];
      for (c = 0; c < 4; c++, curr[2] = rotat(curr[2], home[2])) {
        if (c == 0) curr[2] = save[2];
        for (d = 0; d < 4; d++, curr[3] = rotat(curr[3], home[3])) {
          if (d == 0) curr[3] = save[3];
          if (cool(curr)) {
            if (ans == -1)
              ans = a + b + c + d;
            else
              ans = min(ans, a + b + c + d);
          }
        }
      }
    }
  }
  return ans;
}
int main() {
  ios_base::sync_with_stdio(0);
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) cout << solve() << endl;
  return 0;
}
