#include <bits/stdc++.h>
using namespace std;
struct Point {
  int x, y;
  Point(int _x = 0, int _y = 0) : x(_x), y(_y) {}
  Point rotate() { return Point(-y, x); }
  Point operator-(const Point p) { return Point(x - p.x, y - p.y); }
  Point operator+(const Point p) { return Point(x + p.x, y + p.y); }
  Point rotate(int k) {
    Point now = Point(x, y);
    for (int i = (0); i < (k); i++) now = now.rotate();
    return now;
  }
};
struct Mole {
  Point curr, home;
  Mole() {}
  Mole(Point c, Point h) {
    curr = c;
    home = h;
  }
  Point rotate(int k) {
    Point now = curr - home;
    now = now.rotate(k);
    return now + home;
  }
} m[4];
long long dist(Point a, Point b) {
  return 1LL * (a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y);
}
bool check(Point p1, Point p2, Point p3, Point p4) {
  map<long long, int>::iterator it;
  map<long long, int> mp;
  mp[dist(p1, p2)]++;
  mp[dist(p1, p3)]++;
  mp[dist(p1, p4)]++;
  mp[dist(p2, p3)]++;
  mp[dist(p2, p4)]++;
  mp[dist(p3, p4)]++;
  long long a1 = 1, a2 = 10;
  bool ok1 = false, ok2 = false, ok3 = (mp.size() == 2);
  for (it = mp.begin(); it != mp.end(); it++) {
    if (it->second == 4) ok1 = true, a1 = it->first;
    if (it->second == 2) ok2 = true, a2 = it->first;
  }
  return ok1 && ok2 && ok3 && (a2 == a1 * 2);
}
int main(int argc, char** argv) {
  int N, x1, y1, x2, y2;
  scanf("%d", &N);
  for (int n = (0); n < (N); n++) {
    int ans = 100;
    for (int i = (0); i < (4); i++) {
      scanf("%d%d", &x1, &y1);
      scanf("%d%d", &x2, &y2);
      m[i] = Mole(Point(x1, y1), Point(x2, y2));
    }
    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++) {
            Point p1 = m[0].rotate(a);
            Point p2 = m[1].rotate(b);
            Point p3 = m[2].rotate(c);
            Point p4 = m[3].rotate(d);
            if (check(p1, p2, p3, p4)) ans = min(ans, a + b + c + d);
          }
    if (ans == 100) ans = -1;
    printf("	%d\n", ans);
  }
  return 0;
}
