#include <bits/stdc++.h>
using namespace std;
bool check(int x1, int y1, int x2, int y2, int x3, int y3, int x4, int y4) {
  int p1p2 = (x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1);
  int p2p3 = (x3 - x2) * (x3 - x2) + (y3 - y2) * (y3 - y2);
  int p2p4 = (x4 - x2) * (x4 - x2) + (y4 - y2) * (y4 - y2);
  if (!p1p2 || !p2p3 || !p2p4) return false;
  if (p1p2 == p2p4) {
    x3 = x3 + x4 - (x4 = x3);
    y3 = y3 + y4 - (y4 = y3);
  } else if (p2p3 == p2p4) {
    x1 = x1 + x4 - (x4 = x1);
    y1 = y1 + y4 - (y4 = y1);
  } else if (p1p2 != p2p3)
    return false;
  p1p2 = (x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1);
  p2p3 = (x3 - x2) * (x3 - x2) + (y3 - y2) * (y3 - y2);
  int p1p4 = (x1 - x4) * (x1 - x4) + (y1 - y4) * (y1 - y4);
  int p3p4 = (x3 - x4) * (x3 - x4) + (y3 - y4) * (y3 - y4);
  if (!p1p2 || !p2p3 || !p1p4 || !p3p4) return false;
  if (!(p1p4 == p2p3 && p3p4 == p1p2)) return false;
  if (((y2 - y1) * (y3 - y2) + (x2 - x1) * (x3 - x2)) == 0 &&
      ((y4 - y1) * (y3 - y4) + (x4 - x1) * (x3 - x4)) == 0)
    return true;
  else
    return false;
}
int main() {
  int t;
  cin >> t;
  int s[4] = {0, 1, 0, -1};
  int c[4] = {1, 0, -1, 0};
  while (t--) {
    int a1, b1, x1, y1, X1, Y1, a2, b2, x2, y2, X2, Y2, a3, b3, x3, y3, X3, Y3,
        a4, b4, x4, y4, X4, Y4;
    int min = 1000;
    min *= 1000;
    min *= 100;
    cin >> x1 >> y1 >> a1 >> b1;
    cin >> x2 >> y2 >> a2 >> b2;
    cin >> x3 >> y3 >> a3 >> b3;
    cin >> x4 >> y4 >> a4 >> b4;
    for (int i = 0; i < 4; i++) {
      X4 = (x4 - a4) * c[i] - (y4 - b4) * s[i] + a4;
      Y4 = (y4 - b4) * c[i] + (x4 - a4) * s[i] + b4;
      for (int a = 0; a < 4; a++) {
        X3 = (x3 - a3) * c[a] - (y3 - b3) * s[a] + a3;
        Y3 = (y3 - b3) * c[a] + (x3 - a3) * s[a] + b3;
        for (int b = 0; b < 4; b++) {
          X2 = (x2 - a2) * c[b] - (y2 - b2) * s[b] + a2;
          Y2 = (y2 - b2) * c[b] + (x2 - a2) * s[b] + b2;
          for (int d = 0; d < 4; d++) {
            X1 = (x1 - a1) * c[d] - (y1 - b1) * s[d] + a1;
            Y1 = (y1 - b1) * c[d] + (x1 - a1) * s[d] + b1;
            if (check(X1, Y1, X2, Y2, X3, Y3, X4, Y4)) {
              if (i + a + b + d < min) min = i + a + b + d;
            }
          }
        }
      }
    }
    if (min == 100000000) min = -1;
    cout << min << endl;
  }
  return 0;
}
