#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 7;
const int mod = 1000000007;
struct Point {
  int x, y, a, b;
  int t;
  Point() : t(0) {}
  bool operator<(const Point& k) const { return x == k.x ? y < k.y : x < k.x; }
} point[4], status[maxn][4], fuck[4];
void hehe(int id) {
  int tx = fuck[id].b + fuck[id].a - fuck[id].y;
  int ty = fuck[id].b - fuck[id].a + fuck[id].x;
  fuck[id].x = tx;
  fuck[id].y = ty;
}
int dis(Point a, Point b) {
  return (a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y);
}
bool mid(Point a, Point b, Point c, Point d) {
  return (a.x + b.x == c.x + d.x) && (a.y + b.y == c.y + d.y);
}
bool judge() {
  for (int i = 0; i < 4; ++i) {
    for (int j = i + 1; j < 4; ++j) {
      if (dis(fuck[i], fuck[j]) == 0) return false;
    }
  }
  if (dis(fuck[0], fuck[1]) == dis(fuck[2], fuck[3]) &&
      mid(fuck[0], fuck[1], fuck[2], fuck[3]) &&
      (fuck[0].x - fuck[1].x) * (fuck[2].x - fuck[3].x) +
              (fuck[0].y - fuck[1].y) * (fuck[2].y - fuck[3].y) ==
          0)
    return true;
  if (dis(fuck[0], fuck[2]) == dis(fuck[1], fuck[3]) &&
      mid(fuck[0], fuck[2], fuck[1], fuck[3]) &&
      (fuck[0].x - fuck[2].x) * (fuck[1].x - fuck[3].x) +
              (fuck[0].y - fuck[2].y) * (fuck[1].y - fuck[3].y) ==
          0)
    return true;
  if (dis(fuck[0], fuck[3]) == dis(fuck[1], fuck[2]) &&
      mid(fuck[0], fuck[3], fuck[1], fuck[2]) &&
      (fuck[0].x - fuck[3].x) * (fuck[1].x - fuck[2].x) +
              (fuck[0].y - fuck[3].y) * (fuck[1].y - fuck[2].y) ==
          0)
    return true;
  return false;
}
int main() {
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  while (n--) {
    for (int i = 0; i < 4; ++i) {
      cin >> point[i].x >> point[i].y >> point[i].a >> point[i].b;
    }
    int ans = 23333;
    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) {
            int t;
            memcpy(fuck, point, sizeof fuck);
            t = a;
            while (t--) hehe(0);
            t = b;
            while (t--) hehe(1);
            t = c;
            while (t--) hehe(2);
            t = d;
            while (t--) hehe(3);
            if (judge()) ans = min(ans, a + b + c + d);
          }
        }
      }
    }
    if (ans == 23333)
      cout << -1 << endl;
    else
      cout << ans << endl;
  }
  return 0;
}
