#include <bits/stdc++.h>
using namespace std;
struct data {
  int x, y, a, b;
} d[512];
struct data rot(const struct data &A, int b) {
  struct data t = A;
  int v1 = A.x - A.a;
  int v2 = A.y - A.b;
  t.x -= A.a;
  t.y -= A.b;
  for (int i = 0; i < b; i++) {
    int tx, ty;
    tx = -t.y;
    ty = t.x;
    t.x = tx;
    t.y = ty;
  }
  t.x += A.a;
  t.y += A.b;
  return t;
};
bool isSquare(struct data *A) {
  int min_x, min_y;
  int max_x, max_y;
  int dx, dy;
  int cnt = 0;
  min_x = min_y = max_x = max_y = 1e8;
  for (int i = 0; i < 4; i++)
    for (int j = i + 1; j < 4; j++)
      if (A[i].x == A[j].x && A[i].y == A[j].y) return 0;
  for (int i = 0; i < 4; i++) {
    if (min_x == 1e8 || min_x > A[i].x) min_x = A[i].x;
    if (min_y == 1e8 || min_y > A[i].y) min_y = A[i].y;
    if (max_x == 1e8 || max_x < A[i].x) max_x = A[i].x;
    if (max_y == 1e8 || max_y < A[i].y) max_y = A[i].y;
  }
  dx = max_x - min_x;
  dy = max_y - min_y;
  int b = -1;
  if (dx == 0 || dy == 0) return 0;
  for (int i = 0; i < 4; i++) {
    if (min_x == A[i].x && min_y == A[i].y) b = i;
  }
  if (b == -1) {
    for (int i = 0; i < 4; i++) {
      for (int j = 0; j < 4; j++) {
        cnt = 0;
        if (i == j) continue;
        int dx = A[j].x - A[i].x;
        int dy = A[j].y - A[i].y;
        for (int k = 0; k < 4; k++) {
          if (k == i || k == j) continue;
          if (A[k].x == A[i].x + dx - dy && A[k].y == A[i].y + dx + dy) cnt++;
          if (A[k].y == A[i].y + dx && A[k].x == A[i].x - dy) cnt++;
        }
        if (cnt == 2) return 1;
      }
    }
    return 0;
  }
  if (dx != dy) return 0;
  cnt = 0;
  for (int i = 0; i < 4; i++) {
    if (A[i].x == A[b].x + dx && A[i].y == A[b].y) cnt++;
    if (A[i].x == A[b].x + dx && A[i].y == A[b].y + dy) cnt++;
    if (A[i].x == A[b].x && A[i].y == A[b].y + dy) cnt++;
  }
  return (cnt == 3);
}
int dfs(int x, struct data *A) {
  if (x == 4) {
    if (isSquare(A))
      return 0;
    else
      return 100;
  }
  int m = 100;
  for (int i = 0; i < 4; i++) {
    struct data tmp = A[x];
    A[x] = rot(A[x], i);
    m = min(m, dfs(x + 1, A) + i);
    A[x] = tmp;
  }
  return m;
}
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < 4 * n; i++) {
    cin >> d[i].x >> d[i].y >> d[i].a >> d[i].b;
  }
  for (int i = 0; i < n; i++) {
    int v = dfs(0, d + i * 4);
    if (v == 100)
      cout << -1 << endl;
    else
      cout << v << endl;
  }
  return 0;
}
