#include <bits/stdc++.h>
using namespace std;
const int maxn = int(1.5 * 1e7);
const int inf = 1e9 + 7;
const long long ll_inf = 1e18 + 420;
const double eps = 1e-4;
const int N = 1e6 + 7;
const int MAX = 2e5 + 9;
const int mod = 1e9 + 7;
const long double pi = 3.14159265359;
int n;
int a[4], b[4], x[4], y[4];
int ans;
long long d[6];
long long dist(int i, int j) {
  return (long long)(x[i] - x[j]) * (x[i] - x[j]) +
         (long long)(y[i] - y[j]) * (y[i] - y[j]);
}
bool check() {
  int tot = 0;
  for (int i = 0; i < 4; i++) {
    for (int j = i + 1; j < 4; j++) {
      d[tot++] = dist(i, j);
    }
  }
  sort(d, d + tot);
  if (d[0] == 0) return 0;
  for (int i = 1; i < 4; i++) {
    if (d[i] != d[0]) return 0;
  }
  if (d[4] != d[5]) return 0;
  return 1;
}
void dfs(int u, int cnt) {
  if (u == 4) {
    if (check()) {
      ans = min(ans, cnt);
    }
    return;
  }
  for (int i = 0; i < 4; i++) {
    dfs(u + 1, cnt + i);
    int xx = x[u] - a[u], yy = y[u] - b[u];
    x[u] = -yy + a[u];
    y[u] = xx + b[u];
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  scanf("%d", &n);
  while (n--) {
    for (int i = 0; i < 4; i++) {
      scanf("%d%d%d%d", &x[i], &y[i], &a[i], &b[i]);
    }
    ans = 1000;
    dfs(0, 0);
    if (ans == 1000) ans = -1;
    printf("%d\n", ans);
  }
}
