#include <bits/stdc++.h>
using namespace std;
int INF = 0x3f3f3f3f;
pair<int, int> p[4], a[4], t[4];
int ans;
long long d[6];
long long dis(pair<int, int> a, pair<int, int> b) {
  return 1ll * (a.first - b.first) * (a.first - b.first) +
         1ll * (a.second - b.second) * (a.second - b.second);
}
int judge() {
  d[0] = dis(t[0], t[1]);
  d[1] = dis(t[0], t[2]);
  d[2] = dis(t[0], t[3]);
  d[3] = dis(t[1], t[2]);
  d[4] = dis(t[1], t[3]);
  d[5] = dis(t[2], t[3]);
  sort(d, d + 6);
  if (d[0] != 0 && d[0] == d[1] && d[1] == d[2] && d[2] == d[3] &&
      2 * d[3] == d[4] && d[4] == d[5]) {
    return 1;
  }
  return 0;
}
void change(pair<int, int> &a, pair<int, int> b, int c) {
  a.first -= b.first;
  a.second -= b.second;
  int t;
  for (int i = 0; i < c; i++) {
    t = a.first;
    a.first = -a.second;
    a.second = t;
  }
  a.first += b.first;
  a.second += b.second;
}
void work(int c1, int c2, int c3, int c4, int sum) {
  copy(p, p + 4, t);
  change(t[0], a[0], c1);
  change(t[1], a[1], c2);
  change(t[2], a[2], c3);
  change(t[3], a[3], c4);
  if (judge()) {
    ans = min(ans, sum);
  }
}
int main() {
  int T;
  scanf("%d", &T);
  while (T--) {
    ans = INF;
    for (int i = 0; i < 4; i++) {
      scanf("%d%d%d%d", &p[i].first, &p[i].second, &a[i].first, &a[i].second);
    }
    for (int i = 0; i < 4; i++) {
      for (int j = 0; j < 4; j++) {
        for (int k = 0; k < 4; k++) {
          for (int l = 0; l < 4; l++) {
            work(i, j, k, l, i + j + k + l);
          }
        }
      }
    }
    if (ans == INF) {
      puts("-1");
    } else {
      printf("%d\n", ans);
    }
  }
}
