#include <bits/stdc++.h>
using namespace std;
const int64_t MOD = 1e9 + 9;
const int64_t INF = 1e18;
void io(string s1 = "input.txt", string s2 = "output.txt") {
  freopen(s1.c_str(), "r", stdin);
  freopen(s2.c_str(), "w", stdout);
}
pair<int64_t, int64_t> rotate(pair<int64_t, int64_t> &p,
                              pair<int64_t, int64_t> &o) {
  pair<int64_t, int64_t> np = p;
  np.first -= o.first;
  np.second -= o.second;
  pair<int64_t, int64_t> tmp = np;
  np.first = -tmp.second;
  np.second = tmp.first;
  np.first += o.first;
  np.second += o.second;
  return np;
}
int64_t dist(pair<int64_t, int64_t> &p1, pair<int64_t, int64_t> &p2) {
  return (p1.first - p2.first) * (p1.first - p2.first) +
         (p1.second - p2.second) * (p1.second - p2.second);
}
bool validSquare(pair<int64_t, int64_t> &p1, pair<int64_t, int64_t> &p2,
                 pair<int64_t, int64_t> &p3, pair<int64_t, int64_t> &p4) {
  vector<pair<int64_t, int64_t>> points = {p1, p2, p3, p4};
  set<int64_t> lengths;
  for (int64_t i = 0; i < 4; i++) {
    for (int64_t j = i + 1; j < 4; j++) {
      int64_t curr = dist(points[i], points[j]);
      if (curr != 0)
        lengths.insert(curr);
      else
        return false;
    }
  }
  return lengths.size() == 2;
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int64_t n;
  cin >> n;
  for (int64_t i = 1; i <= n; i++) {
    vector<pair<pair<int64_t, int64_t>, pair<int64_t, int64_t>>> v;
    for (int64_t j = 0; j < 4; j++) {
      int64_t x, y, a, b;
      cin >> x >> y >> a >> b;
      v.push_back({{x, y}, {a, b}});
    }
    int64_t ans = INF;
    for (int64_t q = 0; q <= 3; q++) {
      for (int64_t w = 0; w <= 3; w++) {
        for (int64_t e = 0; e <= 3; e++) {
          for (int64_t r = 0; r <= 3; r++) {
            vector<pair<pair<int64_t, int64_t>, pair<int64_t, int64_t>>> tmp =
                v;
            for (int64_t a = 0; a < q; a++)
              tmp[0].first = rotate(tmp[0].first, tmp[0].second);
            for (int64_t a = 0; a < w; a++)
              tmp[1].first = rotate(tmp[1].first, tmp[1].second);
            for (int64_t a = 0; a < e; a++)
              tmp[2].first = rotate(tmp[2].first, tmp[2].second);
            for (int64_t a = 0; a < r; a++)
              tmp[3].first = rotate(tmp[3].first, tmp[3].second);
            if (validSquare(tmp[0].first, tmp[1].first, tmp[2].first,
                            tmp[3].first))
              ans = min(ans, q + w + e + r);
          }
        }
      }
    }
    if (ans == INF) ans = -1;
    cout << ans << "\n";
  }
}
