#include <bits/stdc++.h>
using namespace std;
const long long M = 1e9 + 9;
long long ans;
long long x[5], y[5], a[5], b[5], d[10];
long long dist(long long i, long long j) {
  return (x[i] - x[j]) * (x[i] - x[j]) + (y[i] - y[j]) * (y[i] - y[j]);
}
bool check() {
  long long tot = 0;
  for (long long i = 1; i <= 3; i++) {
    for (long long j = i + 1; j <= 4; j++) d[tot++] = dist(i, j);
  }
  sort(d, d + tot);
  if (d[0] == 0) return false;
  for (long long y = 1; y <= 3; y++) {
    if (d[y] != d[0]) return false;
  }
  if (d[4] != d[5]) return false;
  return true;
}
void dfs(long long p, long long cnt) {
  if (p == 5) {
    if (check()) ans = min(ans, cnt);
    return;
  }
  for (long long i = 1; i <= 4; i++) {
    dfs(p + 1, cnt + i - 1);
    long long xx = x[p] - a[p];
    long long xy = y[p] - b[p];
    x[p] = -xy + a[p];
    y[p] = xx + b[p];
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long n;
  cin >> n;
  while (n--) {
    for (long long i = 1; i <= 4; i++) cin >> x[i] >> y[i] >> a[i] >> b[i];
    ans = LONG_MAX;
    dfs(1, 0);
    if (ans == LONG_MAX) ans = -1;
    cout << ans << "\n";
  }
}
