#include <bits/stdc++.h>
using namespace std;
int n;
int d[4][2] = {{1, 1}, {-1, 1}, {-1, -1}, {1, -1}};
int ai[4], aj[4], ui[4], uj[4];
bool chk(int ps[][2]) {
  int dist[4] = {0, 0, 0, 0};
  bool ret = true;
  int md = 0;
  for (int i = 0; i < 4; i++) {
    bool ok = false;
    for (int j = 0; j < 4; j++)
      if (i != j) {
        for (int k = 0; k < 4; k++)
          if (k != j && k != i) {
            int a = ps[j][0] - ps[i][0];
            int b = ps[j][1] - ps[i][1];
            int c = ps[k][0] - ps[i][0];
            int d = ps[k][1] - ps[i][1];
            if (ps[j][0] == ps[i][0] && ps[j][1] == ps[i][1]) return false;
            if (ps[k][0] == ps[i][0] && ps[k][1] == ps[i][1]) return false;
            if (ps[k][0] == ps[j][0] && ps[k][1] == ps[j][1]) return false;
            if (a * c + b * d == 0) {
              if (a * a + b * b == c * c + d * d) {
                ok = true;
                if (md != 0 && a * a + b * b != md) return false;
                md = a * a + b * b;
              }
            }
          }
      }
    ret &= ok;
  }
  return ret;
}
int solve() {
  int ret = 0x3f3f3f3f;
  int j[4] = {0, 0, 0, 0};
  int ps[4][2];
  for (j[0] = 0; j[0] < 4; j[0]++)
    for (j[1] = 0; j[1] < 4; j[1]++)
      for (j[2] = 0; j[2] < 4; j[2]++)
        for (j[3] = 0; j[3] < 4; j[3]++) {
          for (int i = 0; i < 4; i++) {
            ps[i][0] = (ui[i] - ai[i]) * d[j[i]][0];
            ps[i][1] = (uj[i] - aj[i]) * d[j[i]][1];
            if (j[i] % 2 != 0) swap(ps[i][0], ps[i][1]);
            ps[i][0] += ai[i];
            ps[i][1] += aj[i];
          }
          if (chk(ps)) {
            ret = min(ret, j[0] + j[1] + j[2] + j[3]);
          }
        }
  return ret;
}
int main(void) {
  cin >> n;
  for (int i = 0; i < 4 * n; i++) {
    cin >> uj[i % 4] >> ui[i % 4] >> aj[i % 4] >> ai[i % 4];
    if (i % 4 == 3) {
      int ans = solve();
      cout << ((ans < 0x3f3f3f3f) ? ans : -1) << "\n";
    }
  }
  return 0;
}
