#include <bits/stdc++.h>
using namespace std;
const int INFI = 1 << 28;
const long long int INFL = 1LL << 60;
const double INFD = 1e+300;
const float INFF = 1e+100;
const double EPS = 1e-8;
pair<int, int> rotate(pair<int, int> a, pair<int, int> base, int r) {
  a.first -= base.first;
  a.second -= base.second;
  for (int i = 0; i < r; i++) {
    swap(a.first, a.second);
    a.first *= -1;
  }
  a.first += base.first;
  a.second += base.second;
  return a;
}
double dist(pair<int, int> a, pair<int, int> b) {
  int x1 = a.first, x2 = b.first;
  int y1 = a.second, y2 = b.second;
  return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
}
bool IsSquare(vector<pair<int, int> > p) {
  sort(p.begin(), p.end());
  swap(p[2], p[3]);
  double d = dist(p[3], p[0]);
  for (int i = 0; i < 4; i++) {
    for (int j = i + 1; j < 4; j++) {
      if (dist(p[i], p[j]) < 1e-8) return false;
    }
  }
  for (int i = 0; i < 3; i++) {
    if (d < 1e-8 || dist(p[i], p[i + 1]) < 1e-8 ||
        abs(d - dist(p[i], p[i + 1])) > 1e-8)
      return false;
  }
  if (abs(dist(p[0], p[2]) - dist(p[1], p[3])) > 1e-8) return false;
  return true;
}
int main() {
  cout.setf(ios::fixed);
  cout.precision(10);
  ios_base::sync_with_stdio(false);
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    vector<pair<int, int> > p(4);
    vector<pair<int, int> > home(4);
    for (int m = 0; m < 4; m++) {
      cin >> p[m].first >> p[m].second >> home[m].first >> home[m].second;
    }
    int minCost = 1 << 28;
    for (int s = 0; s < 4 * 4 * 4 * 4; s++) {
      vector<pair<int, int> > pos(4);
      int cost = 0;
      for (int j = 0; j < 4; j++) {
        int tmp = 1;
        for (int k = 0; k < j; k++) tmp *= 4;
        int r = s / tmp % 4;
        cost += r;
        pos[j] = rotate(p[j], home[j], r);
      }
      if (IsSquare(pos)) {
        minCost = min(minCost, cost);
      }
    }
    if (minCost == (1 << 28))
      cout << -1 << endl;
    else
      cout << minCost << endl;
  }
  return 0;
}
