#include <bits/stdc++.h>
using namespace std;
int n;
int a[4], b[4], x[4], y[4];
pair<int, int> rot(pair<int, int> cur, int a, int b) {
  int difx = cur.first - a;
  int dify = cur.second - b;
  swap(difx, dify);
  difx *= -1;
  return make_pair(a + difx, b + dify);
}
long long dist(int a, int b, int c, int d) {
  return (a - c) * (a - c) + (b - d) * (b - d);
}
bool square(vector<pair<int, int> > g) {
  sort(g.begin(), g.end());
  int m = unique(g.begin(), g.end()) - g.begin();
  if (m != 4) return 0;
  swap(g[3], g[2]);
  long long s = -1;
  for (int i = 0; i < 4; ++i) {
    long long r = dist(g[i].first, g[i].second, g[(i + 1) % 4].first,
                       g[(i + 1) % 4].second);
    if (r == 0) return 0;
    if (s == -1) s = r;
    if (s != r) return 0;
  }
  swap(g[2], g[3]);
  return dist(g[0].first, g[0].second, g[3].first, g[3].second) &&
         dist(g[0].first, g[0].second, g[3].first, g[3].second) ==
             dist(g[1].first, g[1].second, g[2].first, g[2].second);
}
int main() {
  cin >> n;
  while (n--) {
    for (int i = 0; i < 4; ++i) cin >> x[i] >> y[i] >> a[i] >> b[i];
    vector<pair<int, int> > v[4];
    int res = 99;
    for (int i = 0; i < 4; ++i) {
      v[i].push_back(make_pair(x[i], y[i]));
      for (int j = 0; j < 3; ++j) v[i].push_back(rot(v[i].back(), a[i], b[i]));
    }
    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) {
            vector<pair<int, int> > g;
            g.push_back(v[0][i]);
            g.push_back(v[1][j]);
            g.push_back(v[2][k]);
            g.push_back(v[3][l]);
            if (square(g)) res = min(res, i + j + k + l);
          }
        }
      }
    }
    if (res == 99) res = -1;
    cout << res << endl;
  }
}
