#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
const long long INF = 4e18;
const int inf = 2e9;
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }
pair<int, int> rot(pair<pair<int, int>, pair<int, int> > tt, int pos) {
  int x = tt.first.first;
  int y = tt.first.second;
  int a = tt.second.first;
  int b = tt.second.second;
  int dx = a - x;
  int dy = y - b;
  if (pos == 0) {
    return make_pair(a - dx, b + dy);
  }
  if (pos == 1) {
    return make_pair(a - dy, b - dx);
  }
  if (pos == 2) {
    return make_pair(a + dx, b - dy);
  }
  return make_pair(a + dy, b + dx);
}
int i, j, k, l;
pair<pair<int, int>, pair<int, int> > tes[4];
long long dist(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);
}
bool isSame(vector<long long> a, vector<long long> b) {
  int ii, jj;
  for (ii = 0; ii < 4; ++ii) {
    if (a[ii] != b[ii]) return 0;
  }
  return 1;
}
bool rect(vector<pair<int, int> > points) {
  int ii, jj;
  vector<long long> dis;
  bool allZero = 1;
  for (jj = 0; jj < 4; ++jj) {
    long long cur = dist(points[0], points[jj]);
    dis.push_back(cur);
    if (cur) allZero = 0;
  }
  if (allZero) return 0;
  sort(dis.begin(), dis.end());
  if (dis[1] != dis[2] || dis[2] * 2 != dis[3]) return 0;
  for (ii = 1; ii <= 3; ++ii) {
    vector<long long> temp;
    for (jj = 0; jj < 4; ++jj) {
      temp.push_back(dist(points[ii], points[jj]));
    }
    sort(temp.begin(), temp.end());
    if (!isSame(dis, temp)) return 0;
  }
  return 1;
}
int isRec() {
  vector<pair<int, int> > temp;
  temp.push_back(rot(tes[0], i));
  temp.push_back(rot(tes[1], j));
  temp.push_back(rot(tes[2], k));
  temp.push_back(rot(tes[3], l));
  if (!rect(temp)) return inf;
  return i + j + k + l;
}
int main(void) {
  int n;
  scanf("%d", &n);
  while (n--) {
    int x, y, a, b;
    for (i = 0; i < 4; ++i) {
      scanf("%d %d %d %d", &x, &y, &a, &b);
      tes[i] = make_pair(make_pair(x, y), make_pair(a, b));
    }
    int ans = inf;
    for (i = 0; i < 4; ++i)
      for (j = 0; j < 4; ++j)
        for (k = 0; k < 4; ++k)
          for (l = 0; l < 4; ++l) {
            int cur = isRec();
            if (cur < ans) {
              ans = cur;
            }
            ans = min(ans, isRec());
          }
    cout << (ans == inf ? -1 : ans) << endl;
  }
  return 0;
}
