#include <bits/stdc++.h>
using namespace std;
vector<pair<long long int, long long int> > co[55];
vector<long long int> s;
long long int n, x[55], y[55], a[55], b[55];
long long int distance(pair<long long int, long long int> firstone,
                       pair<long long int, long long int> secondone) {
  return (firstone.first - secondone.first) *
             (firstone.first - secondone.first) +
         (firstone.second - secondone.second) *
             (firstone.second - secondone.second);
}
bool check(long long int i, long long int j, long long int k, long long int l) {
  long long int d1, d2, d3;
  s.clear();
  d1 = distance(co[0][i], co[1][j]);
  d2 = distance(co[0][i], co[2][k]);
  d3 = distance(co[0][i], co[3][l]);
  s.push_back(d1);
  s.push_back(d2);
  s.push_back(d3);
  d1 = distance(co[3][l], co[1][j]);
  d2 = distance(co[3][l], co[2][k]);
  d3 = distance(co[1][j], co[2][k]);
  s.push_back(d1);
  s.push_back(d2);
  s.push_back(d3);
  sort(s.begin(), s.end());
  if ((s[0] == s[1] && s[0] == s[2] && s[0] == s[3]) && (s[4] == s[5]) &&
      (2 * s[0] == s[4]) && s[0] != 0)
    return true;
  return false;
}
void solve() {
  long long int i, j, k, l, m, ans = 9223372036854775807;
  for (i = 0; i < 4; i++) {
    for (j = 0; j < 4; j++) {
      for (k = 0; k < 4; k++) {
        for (l = 0; l < 4; l++) {
          if (check(i, j, k, l)) {
            ans = min(ans, i + j + k + l);
          }
        }
      }
    }
  }
  if (ans == 9223372036854775807)
    cout << -1 << '\n';
  else
    cout << ans << '\n';
  return;
}
int main() {
  long long int i, j, tempx, tempy;
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  while (n--) {
    for (i = 0; i < 4; i++) {
      cin >> x[i] >> y[i] >> a[i] >> b[i];
      co[i].clear();
      co[i].push_back(make_pair(x[i], y[i]));
    }
    for (i = 0; i < 4; i++) {
      tempx = x[i] - a[i];
      tempy = y[i] - b[i];
      while (co[i].size() < 4) {
        x[i] = -tempy;
        y[i] = tempx;
        co[i].push_back(make_pair(x[i] + a[i], y[i] + b[i]));
        tempx = x[i];
        tempy = y[i];
      }
    }
    solve();
  }
  return 0;
}
