#include <bits/stdc++.h>
using namespace std;
pair<pair<long long, long long>, pair<long long, long long> > cords[4];
pair<long long, long long> arr[4][4];
pair<long long, long long> h;
long long getDist(pair<long long, long long> a, pair<long long, long long> b) {
  return (a.first - b.first) * (a.first - b.first) +
         (a.second - b.second) * (a.second - b.second);
}
bool cmpfn(pair<long long, long long> a, pair<long long, long long> b) {
  return getDist(h, a) <= getDist(h, b);
}
bool isSquare(pair<long long, long long> a, pair<long long, long long> b,
              pair<long long, long long> c, pair<long long, long long> d) {
  h = a;
  pair<long long, long long> mas[4] = {a, b, c, d};
  sort(mas, mas + 4, cmpfn);
  if ((getDist(mas[0], mas[1]) != getDist(mas[0], mas[2]) ||
       getDist(mas[1], mas[3]) != getDist(mas[2], mas[3]) ||
       getDist(mas[0], mas[1]) != getDist(mas[1], mas[3])) ||
      getDist(mas[1], mas[3]) == 0) {
    return false;
  }
  if (getDist(mas[1], mas[2]) != getDist(mas[0], mas[3]) ||
      getDist(mas[0], mas[3]) == 0)
    return false;
  return true;
}
int main() {
  int n, cur = 0;
  scanf("%d", &n);
  for (int i = 0; i < 4 * n; i++) {
    scanf("%I64d %I64d %I64d %I64d", &cords[i % 4].first.first,
          &cords[i % 4].first.second, &cords[i % 4].second.first,
          &cords[i % 4].second.second);
    if (i % 4 == 3) {
      for (int p = 0; p < 4; p++) {
        long long difx = -cords[p].second.first + cords[p].first.first;
        long long dify = -cords[p].second.second + cords[p].first.second;
        arr[p][0].first = cords[p].second.first + difx;
        arr[p][0].second = cords[p].second.second + dify;
        arr[p][1].first = cords[p].second.first - dify;
        arr[p][1].second = cords[p].second.second + difx;
        arr[p][2].first = cords[p].second.first - difx;
        arr[p][2].second = cords[p].second.second - dify;
        arr[p][3].first = cords[p].second.first + dify;
        arr[p][3].second = cords[p].second.second - difx;
      }
      int ans = 10000;
      for (int a = 0; a < 4; a++)
        for (int b = 0; b < 4; b++)
          for (int c = 0; c < 4; c++)
            for (int d = 0; d < 4; d++) {
              if (isSquare(arr[0][a], arr[1][b], arr[2][c], arr[3][d])) {
                ans = min(ans, a + b + c + d);
              }
            }
      if (ans == 10000) {
        cout << -1 << endl;
      } else {
        cout << ans << endl;
      }
    }
  }
  return 0;
}
