#include <bits/stdc++.h>
using namespace std;
map<long double, int> mp;
long double dist(int x1, int y1, int x2, int y2) {
  return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
}
bool sq(int x1, int y1, int x2, int y2, int x3, int y3, int x4, int y4) {
  mp.clear();
  long double a, b, c, d, e, o;
  a = dist(x1, y1, x2, y2);
  b = dist(x2, y2, x3, y3);
  c = dist(x3, y3, x4, y4);
  d = dist(x4, y4, x1, y1);
  e = dist(x2, y2, x4, y4);
  o = dist(x1, y1, x3, y3);
  mp[a]++;
  mp[b]++;
  mp[c]++;
  mp[d]++;
  mp[e]++;
  mp[o]++;
  if (a == 0 || b == 0 || c == 0 || d == 0 || e == 0 || o == 0) return 0;
  if (mp.size() > 2) return 0;
  if (mp[a] < 4 && mp[e] < 4 && mp[o] < 4) return 0;
  return 1;
}
int main() {
  int n;
  cin >> n;
  vector<vector<pair<pair<int, int>, int> > > points(500);
  for (int i = 0; i < 4 * n; i++) {
    int x, y, a, b;
    cin >> x >> y >> a >> b;
    int X = x - a;
    int Y = y - b;
    points[i].push_back({{X + a, Y + b}, 0});
    points[i].push_back({{-Y + a, X + b}, 1});
    points[i].push_back({{-X + a, -Y + b}, 2});
    points[i].push_back({{Y + a, -X + b}, 3});
  }
  for (int i = 0; i < 4 * n; i += 4) {
    int ans = 1e9;
    for (int j = 0; j < 4; j++) {
      for (int k = 0; k < 4; k++) {
        for (int q = 0; q < 4; q++) {
          for (int z = 0; z < 4; z++) {
            int x1, x2, x3, x4, y1, y2, y3, y4, cost1, cost2, cost3, cost4;
            x1 = points[i][j].first.first;
            y1 = points[i][j].first.second;
            cost1 = points[i][j].second;
            x2 = points[i + 1][k].first.first;
            y2 = points[i + 1][k].first.second;
            cost2 = points[i + 1][k].second;
            x3 = points[i + 2][q].first.first;
            y3 = points[i + 2][q].first.second;
            cost3 = points[i + 2][q].second;
            x4 = points[i + 3][z].first.first;
            y4 = points[i + 3][z].first.second;
            cost4 = points[i + 3][z].second;
            int Tcost = cost1 + cost2 + cost3 + cost4;
            if (sq(x1, y1, x2, y2, x3, y3, x4, y4)) {
              ans = min(Tcost, ans);
            }
          }
        }
      }
    }
    if (ans == 1e9)
      cout << -1 << endl;
    else
      cout << ans << endl;
  }
  return 0;
}
