#include <bits/stdc++.h>
using namespace std;
template <class T>
int getbit(T s, int i) {
  return (s >> i) & 1;
}
template <class T>
T onbit(T s, int i) {
  return s | (T(1) << i);
}
template <class T>
T offbit(T s, int i) {
  return s & (~(T(1) << i));
}
template <class T>
int cntbit(T s) {
  return __builtin_popcountll(s);
}
const int bfsz = 1 << 16;
char bf[bfsz + 5];
int rsz = 0;
int ptr = 0;
char gc() {
  if (rsz <= 0) {
    ptr = 0;
    rsz = (int)fread(bf, 1, bfsz, stdin);
    if (rsz <= 0) return EOF;
  }
  --rsz;
  return bf[ptr++];
}
void ga(char &c) {
  c = EOF;
  while (!isalpha(c)) c = gc();
}
int gs(char s[]) {
  int l = 0;
  char c = gc();
  while (isspace(c)) c = gc();
  while (c != EOF && !isspace(c)) {
    s[l++] = c;
    c = gc();
  }
  s[l] = '\0';
  return l;
}
template <class T>
bool gi(T &v) {
  v = 0;
  char c = gc();
  while (c != EOF && c != '-' && !isdigit(c)) c = gc();
  if (c == EOF) return false;
  bool neg = c == '-';
  if (neg) c = gc();
  while (isdigit(c)) {
    v = v * 10 + c - '0';
    c = gc();
  }
  if (neg) v = -v;
  return true;
}
template <class T>
T gcd(T a, T b) {
  T r;
  while (b != 0) {
    r = a % b;
    a = b;
    b = r;
  }
  return a;
}
template <class T>
T lcm(T a, T b) {
  return a / gcd(a, b) * b;
}
int test;
int x[4], y[4], a[4], b[4], X[4], Y[4], t;
pair<int, int> cal(int r1, int c1, int r2, int c2, int num) {
  if (num == 0) return make_pair(r1, c1);
  return cal(c2 - c1 + r2, r1 - r2 + c2, r2, c2, num - 1);
}
long long sqr(int A) { return A * 1ll * A; }
bool can() {
  vector<long long> V;
  for (int i = 0; i < (4); ++i)
    for (int j = i + 1; j < 4; j++) {
      V.push_back(sqr(X[i] - X[j]) + sqr(Y[i] - Y[j]));
    }
  sort((V).begin(), (V).end());
  if (V[3] == V[0] && V[4] == V[5] && V[4] == V[3] + V[3] && V[0] != 0)
    return true;
  return false;
}
void solve() {
  for (int i = 0; i < (4); ++i) {
    cin >> x[i] >> y[i] >> a[i] >> b[i];
  }
  int M = 1;
  for (int run = 0; run < (4); ++run) M *= 4;
  int res = 1000000005;
  for (int mask = 0; mask < (M); ++mask) {
    int the = mask;
    int num = 0;
    for (int i = 0; i < (4); ++i) {
      t = the % 4;
      the /= 4;
      pair<int, int> P = cal(x[i], y[i], a[i], b[i], t);
      X[i] = P.first;
      Y[i] = P.second;
      num += t;
    }
    if (can()) res = min(res, num);
  }
  if (res >= 1000000005)
    cout << -1 << endl;
  else
    cout << res << endl;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> test;
  for (int itest = 0; itest < (test); ++itest) {
    solve();
  }
  return 0;
}
