#include <bits/stdc++.h>
using namespace std;
bool eq(double a, double b) { return abs(a - b) < 0.00000000000001; }
template <class... Args>
bool eq(double a, double b, Args... args) {
  return eq(a, b) && eq(b, args...);
}
pair<int, int> r(pair<int, int> p, pair<int, int> h, int n) {
  p.first -= h.first, p.second -= h.second;
  for (int i = 0; i < n; i++) p.second = -p.second, swap(p.first, p.second);
  p.first += h.first, p.second += h.second;
  return p;
}
bool second(vector<pair<int, int> > v) {
  sort(v.begin(), v.end());
  return unique(v.begin(), v.end()) == v.end() &&
         (eq(hypot(v[0].first - v[1].first, v[0].second - v[1].second),
             hypot(v[0].first - v[2].first, v[0].second - v[2].second),
             hypot(v[1].first - v[3].first, v[1].second - v[3].second),
             hypot(v[2].first - v[3].first, v[2].second - v[3].second)) &&
          eq(hypot(v[0].first - v[3].first, v[0].second - v[3].second),
             hypot(v[1].first - v[2].first, v[1].second - v[2].second)));
}
int main() {
  int T;
  cin >> T;
  pair<int, int> p[4], h[4];
  while (T--) {
    int ans = 99;
    bool first = 0;
    for (int i = 0; i < 4; i++)
      cin >> p[i].first >> p[i].second >> h[i].first >> h[i].second;
    for (int i = 0; i < 4; i++)
      for (int j = 0; j < 4; j++)
        for (int k = 0; k < 4; k++)
          for (int l = 0; l < 4; l++)
            if (second({r(p[0], h[0], i), r(p[1], h[1], j), r(p[2], h[2], k),
                        r(p[3], h[3], l)}))
              first = 1, ans = min(ans, i + j + k + l);
    cout << (first ? ans : -1) << endl;
  }
}
