#include <bits/stdc++.h>
using namespace std;
struct pos {
  int x, y, a, b;
  pos(int x, int y, int a, int b) : x(x), y(y), a(a), b(b) {}
  pos() {}
} reg[4];
struct point {
  int x, y;
  point(int x, int y) : x(x), y(y) {}
  point() {}
};
int N;
bool operator==(const point &a, const point &b) {
  return a.x == b.x && a.y == b.y;
}
point rotate_by(point a, point o, double deg) {
  point ret = a;
  ;
  for (int i = 0; i < deg; i++) {
    ret.x = o.x + o.y - a.y;
    ret.y = -o.x + o.y + a.x;
    a.x = ret.x;
    a.y = ret.y;
  }
  return ret;
}
long long dis(point a, point b) {
  long long x = a.x - b.x;
  long long y = a.y - b.y;
  return x * x + y * y;
}
bool is_right(point a, point b, point c) {
  long long d[3];
  if (a == b || b == c || a == c) {
    return false;
  }
  d[0] = dis(a, b);
  d[1] = dis(b, c);
  d[2] = dis(c, a);
  if (!d[0]) {
    return false;
  }
  sort(d, d + 3);
  return (d[2] == d[0] + d[1]) && (d[0] == d[1]);
}
bool is_square(point p[]) {
  bool ret = is_right(p[0], p[1], p[2]) && is_right(p[1], p[2], p[3]) &&
             is_right(p[2], p[3], p[0]);
  return ret;
}
int find_res(int step, int cond[4]) {
  if (step == 4) {
    point sq[4];
    int cost = 0;
    for (int i = 0; i < 4; i++) {
      cost += cond[i];
      sq[i] = rotate_by(point(reg[i].x, reg[i].y), point(reg[i].a, reg[i].b),
                        cond[i]);
    }
    if (is_square(sq)) {
      return cost;
    } else {
      return 100;
    };
  }
  int temp[4];
  for (int j = 0; j < 4; j++) {
    temp[j] = cond[j];
  }
  int ret = 100;
  for (int i = 0; i < 4; i++) {
    temp[step] = i;
    ret = min(ret, find_res(step + 1, temp));
  }
  return ret;
}
int main() {
  scanf("%d", &N);
  while (N--) {
    for (int i = 0; i < 4; i++) {
      int x, y, a, b;
      scanf("%d%d%d%d", &x, &y, &a, &b);
      reg[i] = pos(x, y, a, b);
    }
    int cond[4];
    memset(cond, 0, sizeof(cond));
    int got = find_res(0, cond);
    if (got < 16) {
      printf("%d\n", got);
    } else {
      puts("-1");
    }
  }
  return 0;
}
