#include <bits/stdc++.h>
using namespace std;
long long a[4], b[4], x[4], y[4], ans;
bool valid() {
  double d[20];
  long long cnt = 0;
  for (long long i = 0; i < 4; ++i)
    for (long long j = i + 1; j < 4; ++j)
      d[cnt++] =
          ((x[i] - x[j]) * (x[i] - x[j])) + ((y[i] - y[j]) * (y[i] - y[j]));
  sort(d, d + cnt);
  if (!d[0]) return 0;
  for (long long i = 0; i < 4; ++i)
    if (d[i] != d[0]) return 0;
  if (d[4] != d[5]) return 0;
  return 1;
}
void bt(int j, long long m) {
  if (j == 4) {
    if (valid()) ans = min(ans, m);
    return;
  }
  for (int i = 0; i < 4; ++i) {
    bt(j + 1, m + i);
    long long xx = x[j] - a[j];
    long long yy = y[j] - b[j];
    x[j] = -yy + a[j];
    y[j] = xx + b[j];
  }
}
int main() {
  int t;
  cin >> t;
  while (t--) {
    for (int i = 0; i < 4; ++i) cin >> x[i] >> y[i] >> a[i] >> b[i];
    ans = 25;
    bt(0, 0);
    printf("%d\n", ans == 25 ? -1 : ans);
  }
}
