#include <bits/stdc++.h>
using namespace std;
int gcd(int a, int b) {
  while (a && b) a > b ? a %= b : b %= a;
  return a + b;
}
int LCM(int a, int b) { return (a * b) / gcd(a, b); }
long long fast_exp(long long base, long long exp) {
  long long res = 1;
  while (exp > 0) {
    if (exp % 2 == 1)
      res = ((res % 1000000007) * (base % 1000000007)) % 1000000007;
    base = ((base % 1000000007) * (base % 1000000007)) % 1000000007;
    exp /= 2;
  }
  return res % 1000000007;
}
int phi(int n) {
  int result = n;
  for (int i = 2; i * i <= n; ++i)
    if (n % i == 0) {
      while (n % i == 0) n /= i;
      result -= result / i;
    }
  if (n > 1) result -= result / n;
  return result;
}
const int INF = INT_MAX;
const long long INFL = LLONG_MAX;
struct Point {
  int x, y;
};
int distSq(Point p, Point q) {
  return (p.x - q.x) * (p.x - q.x) + (p.y - q.y) * (p.y - q.y);
}
bool isSquare(Point p1, Point p2, Point p3, Point p4) {
  if (p1.x == p2.x && p1.y == p2.y || p1.x == p3.x && p1.y == p3.y ||
      p1.x == p4.x && p1.y == p4.y)
    return 0;
  if (p2.x == p3.x && p2.y == p3.y || p2.x == p4.x && p2.y == p4.y) return 0;
  if (p3.x == p4.x && p3.y == p4.y) return 0;
  int d2 = distSq(p1, p2);
  int d3 = distSq(p1, p3);
  int d4 = distSq(p1, p4);
  if (d2 == d3 && 2 * d2 == d4) {
    int d = distSq(p2, p4);
    return (d == distSq(p3, p4) && d == d2);
  }
  if (d3 == d4 && 2 * d3 == d2) {
    int d = distSq(p2, p3);
    return (d == distSq(p2, p4) && d == d3);
  }
  if (d2 == d4 && 2 * d2 == d3) {
    int d = distSq(p2, p3);
    return (d == distSq(p3, p4) && d == d2);
  }
  return false;
}
int main() {
  std::ios::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  for (int(i) = 0; (i) < (n); (i)++) {
    vector<Point> pos[4];
    for (int(j) = 0; (j) < (4); (j)++) {
      int x, y, a, b;
      cin >> x >> y >> a >> b;
      Point temp;
      temp.x = x;
      temp.y = y;
      pos[j].push_back(temp);
      for (int(k) = 0; (k) < (3); (k)++) {
        x -= a;
        y -= b;
        int xnew = -y;
        int ynew = x;
        x = xnew + a;
        y = ynew + b;
        temp.x = x;
        temp.y = y;
        pos[j].push_back(temp);
      }
    }
    int max1 = 100;
    for (int(a) = 0; (a) < (4); (a)++) {
      for (int(b) = 0; (b) < (4); (b)++) {
        for (int(c) = 0; (c) < (4); (c)++) {
          for (int(d) = 0; (d) < (4); (d)++) {
            if (isSquare(pos[0][a], pos[1][b], pos[2][c], pos[3][d]) == 1) {
              max1 = min(max1, a + b + c + d);
            }
          }
        }
      }
    }
    if (max1 == 100) max1 = -1;
    cout << max1 << '\n';
  }
  return 0;
}
