#include <bits/stdc++.h>
using namespace std;
inline long long sqr(long long x) { return x * x; }
inline long long sdist(pair<int, int> &a, pair<int, int> &b) {
  return sqr(a.first - b.first) + sqr(a.second - b.second);
}
bool check(pair<int, int> &a, pair<int, int> &b, pair<int, int> &c,
           pair<int, int> &d) {
  vector<long long> D;
  D.clear();
  D.push_back(sdist(a, b));
  D.push_back(sdist(a, c));
  D.push_back(sdist(a, d));
  D.push_back(sdist(b, c));
  D.push_back(sdist(b, d));
  D.push_back(sdist(c, d));
  sort(D.begin(), D.end());
  return (D[0] > 0 && D[0] == D[1] && D[0] == D[2] && D[0] == D[3] &&
          D[0] * 2 == D[4] && D[0] * 2 == D[5]);
}
pair<int, int> b[4];
pair<int, int> a[4];
int main() {
  ios_base::sync_with_stdio(false);
  int T;
  cin >> T;
  while (T--) {
    for (int _n(4), i(0); i < _n; i++) {
      cin >> b[i].first >> b[i].second;
      cin >> a[i].first >> a[i].second;
    }
    int ans = 1011111111;
    for (int _n(4), r1(0); r1 < _n; r1++) {
      for (int _n(4), r2(0); r2 < _n; r2++) {
        for (int _n(4), r3(0); r3 < _n; r3++) {
          for (int _n(4), r4(0); r4 < _n; r4++) {
            if (check(b[0], b[1], b[2], b[3]))
              ans = min(ans, r1 + r2 + r3 + r4);
            int x = b[3].first - a[3].first;
            int y = b[3].second - a[3].second;
            b[3] = pair<int, int>(a[3].first - y, a[3].second + x);
          }
          int x = b[2].first - a[2].first;
          int y = b[2].second - a[2].second;
          b[2] = pair<int, int>(a[2].first - y, a[2].second + x);
        }
        int x = b[1].first - a[1].first;
        int y = b[1].second - a[1].second;
        b[1] = pair<int, int>(a[1].first - y, a[1].second + x);
      }
      int x = b[0].first - a[0].first;
      int y = b[0].second - a[0].second;
      b[0] = pair<int, int>(a[0].first - y, a[0].second + x);
    }
    if (ans == 1011111111) {
      cout << -1 << endl;
    } else {
      cout << ans << endl;
    }
  }
  return 0;
}
