#include <bits/stdc++.h>
using namespace std;
struct point {
  int x, y, a, b;
  point Rotate() {
    int dx = x - a, dy = y - b;
    int tx = -dy, ty = dx;
    point res;
    res.x = a + tx;
    res.y = b + ty;
    res.a = a;
    res.b = b;
    return res;
  }
  void input() { scanf("%d%d%d%d", &x, &y, &a, &b); }
  void print() { printf("%d %d\n", x, y); }
};
point save[4];
point s[4];
int per[4];
bool check(point *t) {
  int dx = t[1].x - t[0].x;
  int dy = t[1].y - t[0].y;
  if (dx == 0 && dy == 0) return false;
  int tx = dy, ty = -dx;
  dx = tx;
  dy = ty;
  if (t[1].x + dx == t[2].x && t[1].y + dy == t[2].y)
    ;
  else
    return false;
  tx = dy, ty = -dx;
  dx = tx;
  dy = ty;
  if (t[2].x + dx == t[3].x && t[2].y + dy == t[3].y)
    ;
  else
    return false;
  tx = dy, ty = -dx;
  dx = tx;
  dy = ty;
  if (t[3].x + dx == t[0].x && t[3].y + dy == t[0].y)
    ;
  else
    return false;
  return true;
}
int main() {
  int fo;
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j < 4; j++) save[j].input();
    int ans = 0x3f3f3f3f;
    for (int i0 = 0; i0 < 4; i0++) {
      for (int i1 = 0; i1 < 4; i1++) {
        for (int i2 = 0; i2 < 4; i2++) {
          for (int i3 = 0; i3 < 4; i3++) {
            for (int k = 0; k < 4; k++) per[k] = k;
            for (int tm = 1; tm <= 24; tm++) {
              for (int k = 0; k < 4; k++) {
                s[k] = save[per[k]];
              }
              if (check(s)) {
                if (i0 + i1 + i2 + i3 < ans) {
                  ans = min(ans, i0 + i1 + i2 + i3);
                }
              }
              next_permutation(per, per + 4);
            }
            save[3] = save[3].Rotate();
          }
          save[2] = save[2].Rotate();
        }
        save[1] = save[1].Rotate();
      }
      save[0] = save[0].Rotate();
    }
    if (ans == 0x3f3f3f3f)
      printf("-1\n");
    else
      printf("%d\n", ans);
  }
  return 0;
}
