#include <bits/stdc++.h>
using namespace std;
template <class T>
void dbs(string str, T t) {
  cerr << str << " : " << t << "\n";
}
template <class T, class... S>
void dbs(string str, T t, S... second) {
  int idx = str.find(',');
  cerr << str.substr(0, idx) << " : " << t << ",";
  dbs(str.substr(idx + 1), second...);
}
template <class S, class T>
ostream& operator<<(ostream& os, const pair<S, T>& p) {
  return os << "(" << p.first << ", " << p.second << ")";
}
template <class T>
ostream& operator<<(ostream& os, const vector<T>& p) {
  os << "[ ";
  for (auto& it : p) os << it << " ";
  return os << "]";
}
template <class T>
ostream& operator<<(ostream& os, const set<T>& p) {
  os << "[ ";
  for (auto& it : p) os << it << " ";
  return os << "]";
}
template <class S, class T>
ostream& operator<<(ostream& os, const map<S, T>& p) {
  os << "[ ";
  for (auto& it : p) os << it << " ";
  return os << "]";
}
template <class T>
void prc(T a, T b) {
  cerr << "[";
  for (T i = a; i != b; ++i) {
    if (i != a) cerr << ", ";
    cerr << *i;
  }
  cerr << "]\n";
}
int d(pair<int, int> a, pair<int, int> b) {
  return ((a.first - b.first) * (a.first - b.first) +
          (a.second - b.second) * (a.second - b.second));
}
bool check(vector<pair<int, int> > A) {
  set<pair<int, int> > S;
  for (int(i) = (int)(1); (i) <= (int)(4); (i)++) S.insert(A[i - 1]);
  if ((int)(S).size() < 4) return false;
  bool ans = false;
  ans |=
      ((d(A[0], A[2]) == d(A[1], A[3])) && (d(A[0], A[2]) == d(A[0], A[3])) &&
       (d(A[0], A[2]) == d(A[1], A[2])) && (d(A[0], A[1]) == d(A[2], A[3])));
  swap(A[1], A[2]);
  ans |=
      ((d(A[0], A[2]) == d(A[1], A[3])) && (d(A[0], A[2]) == d(A[0], A[3])) &&
       (d(A[0], A[2]) == d(A[1], A[2])) && (d(A[0], A[1]) == d(A[2], A[3])));
  swap(A[1], A[3]);
  ans |=
      ((d(A[0], A[2]) == d(A[1], A[3])) && (d(A[0], A[2]) == d(A[0], A[3])) &&
       (d(A[0], A[2]) == d(A[1], A[2])) && (d(A[0], A[1]) == d(A[2], A[3])));
  return ans;
}
pair<int, int> R(vector<int>& V, int t) {
  if (t != 0) {
    V[1] -= V[3];
    V[2] -= V[4];
    swap(V[1], V[2]);
    V[1] *= -1;
    V[1] += V[3];
    V[2] += V[4];
  }
  return {V[1], V[2]};
}
int SOL(vector<vector<int> >& V) {
  vector<pair<int, int> > A(4);
  int mini = 1000000009;
  for (int(i) = (int)(0); (i) <= (int)(3); (i)++) {
    A[0] = R(V[1], i);
    for (int(j) = (int)(0); (j) <= (int)(3); (j)++) {
      A[1] = R(V[2], j);
      for (int(k) = (int)(0); (k) <= (int)(3); (k)++) {
        A[2] = R(V[3], k);
        for (int u = 0; u <= 3; u++) {
          A[3] = R(V[4], u);
          if (check(A)) {
            mini = min(mini, i + j + k + u);
          }
        }
        A[3] = R(V[4], 1);
      }
      A[2] = R(V[3], 1);
    }
    A[1] = R(V[2], 1);
  }
  if (mini == 1000000009) return -1;
  return mini;
}
int main() {
  int n;
  scanf("%d", &n);
  vector<vector<int> > V(5, vector<int>(5));
  for (int(i) = (int)(1); (i) <= (int)(n); (i)++) {
    for (int(j) = (int)(1); (j) <= (int)(4); (j)++) {
      scanf("%d%d%d%d", &V[j][1], &V[j][2], &V[j][3], &V[j][4]);
    }
    printf("%d\n", SOL(V));
  }
  return 0;
}
