#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 100, LG = 62;
pair<double, double> clock(pair<double, double> p, pair<double, double> o) {
  double x, y;
  x = -(p.second - o.second);
  y = p.first - o.first;
  return make_pair(x + o.first, y + o.second);
}
bool sq(double x1, double x2, double x3, double x4, double y1, double y2,
        double y3, double y4) {
  pair<double, double> p = make_pair((x1 + x3) / 2, (y1 + y3) / 2);
  pair<double, double> q = make_pair(x1, y1);
  if (make_pair(x1, y1) == make_pair(x2, y2) ||
      make_pair(x1, y1) == make_pair(x3, y3) ||
      make_pair(x1, y1) == make_pair(x4, y4) ||
      make_pair(x3, y3) == make_pair(x2, y2) ||
      make_pair(x4, y4) == make_pair(x2, y2) ||
      make_pair(x3, y3) == make_pair(x4, y4))
    return 0;
  q = clock(q, p);
  if (q != make_pair(x2, y2)) return 0;
  q = clock(q, p);
  if (q != make_pair(x3, y3)) return 0;
  q = clock(q, p);
  if (q != make_pair(x4, y4)) return 0;
  return 1;
}
int main() {
  ios::sync_with_stdio(0);
  long long int q;
  cin >> q;
  while (q--) {
    pair<double, double> xy[5], ab[5];
    for (int i = 0; i < 4; i++) {
      cin >> xy[i].first >> xy[i].second >> ab[i].first >> ab[i].second;
    }
    long long int ans = 1e18;
    for (int i = 0; i < 256; i++) {
      int i1 = i;
      int b[6];
      b[0] = i1 % 4;
      i1 /= 4;
      b[1] = i1 % 4;
      i1 /= 4;
      b[2] = i1 % 4;
      i1 /= 4;
      b[3] = i1 % 4;
      for (int k = 0; k < 4; k++)
        for (int j = 0; j < b[k]; j++) xy[k] = clock(xy[k], ab[k]);
      vector<long long int> v = {0, 1, 2, 3};
      for (int j = 0; j < 24; j++) {
        if (sq(xy[v[0]].first, xy[v[1]].first, xy[v[2]].first, xy[v[3]].first,
               xy[v[0]].second, xy[v[1]].second, xy[v[2]].second,
               xy[v[3]].second)) {
          ans = min(ans, 0ll + b[0] + b[1] + b[2] + b[3]);
        }
        next_permutation(v.begin(), v.end());
      }
      for (int k = 0; k < 4; k++)
        for (int j = 0; j < 4 - b[k]; j++) xy[k] = clock(xy[k], ab[k]);
    }
    if (ans == 1e18)
      cout << -1 << '\n';
    else
      cout << ans << '\n';
  }
}
