#include <bits/stdc++.h>
using namespace std;
const int maxn = 4 * 123;
int xx[4] = {-1, 1, -1, 1};
int yy[4] = {-1, -1, 1, 1};
struct he {
  int x1[5], y1[5], x2, y2;
} HMM[maxn];
int t;
int ok;
int x[5], y[5];
int flag(int x1, int y1, int x2, int y2, int x3, int y3) {
  long long need =
      ((long long)(x2 - x3)) * (y1 - y3) - ((long long)((x1 - x3))) * (y2 - y3);
  if (need == 0)
    return 1;
  else if (need < 0)
    return 2;
  return 3;
}
bool can() {
  for (int i = 1; i <= 4; i++) {
    for (int j = 1; j <= 4; j++) {
      if (i != j && x[i] == x[j] && y[i] == y[j]) return false;
    }
  }
  int ci[5];
  bool used[5];
  memset(ci, 0, sizeof(ci));
  memset(used, 0, sizeof(ci));
  ci[1] = 1;
  long long isok = -1;
  int stt = 1;
  while (stt <= 3) {
    int now = ci[stt];
    used[ci[stt]] = 1;
    long long MIN = -1;
    int idx = -1;
    for (int j = 1; j <= 4; j++) {
      if (!used[j]) {
        long long len = ((long long)(x[j] - x[now])) * (x[j] - x[now]) +
                        ((long long)(y[j] - y[now])) * (y[j] - y[now]);
        if (MIN == -1) {
          MIN = len;
          idx = j;
        } else if (MIN > len) {
          MIN = len;
          idx = j;
        }
      }
    }
    if (isok == -1)
      isok = MIN;
    else if (isok != MIN)
      return false;
    else {
      stt++;
      ci[stt] = idx;
    }
  }
  if (((long long)(x[ci[1]] - x[ci[4]])) * (x[ci[1]] - x[ci[4]]) +
          ((long long)(y[ci[1]] - y[ci[4]])) * (y[ci[1]] - y[ci[4]]) ==
      isok) {
    if ((((long long)(y[ci[3]])) - (y[ci[4]])) * (y[ci[1]] - y[ci[4]]) ==
        (((long long)(x[ci[1]])) - (x[ci[4]])) * (x[ci[3]] - x[ci[4]]) * -1) {
      return true;
    } else
      return false;
  } else
    return false;
}
void cal(int idx) {
  int x1 = HMM[idx].x1[1];
  int y1 = HMM[idx].y1[1];
  int x3 = HMM[idx].x2;
  int y3 = HMM[idx].y2;
  int a = abs(x1 - x3);
  int b = abs(y1 - y3);
  for (int i = 0; i < 4; i++) {
    int nowx = a * xx[i];
    int nowy = b * yy[i];
    if (flag(x1, y1, x3 + nowx, y3 + nowy, x3, y3) == 1 &&
        (x1 != x3 + nowx || y1 != y3 + nowy)) {
      HMM[idx].x1[3] = x3 + nowx;
      HMM[idx].y1[3] = y3 + nowy;
      int xx1 = (x1 + x3 + nowx + y3 + nowy - y1) / 2;
      int yy1 = (y1 + y3 + nowy + x1 - x3 - nowx) / 2;
      int xx2 = (x1 + x3 + nowx - y3 - nowy + y1) / 2;
      int yy2 = (y1 + y3 + nowy - x1 + x3 + nowx) / 2;
      if (flag(x1, y1, xx1, yy1, x3, y3) == 2) {
        HMM[idx].x1[2] = xx1;
        HMM[idx].y1[2] = yy1;
        HMM[idx].x1[4] = xx2;
        HMM[idx].y1[4] = yy2;
      } else {
        HMM[idx].x1[2] = xx2;
        HMM[idx].y1[2] = yy2;
        HMM[idx].x1[4] = xx1;
        HMM[idx].y1[4] = yy1;
      }
      break;
    }
  }
}
void DYGANDQYM(int now, int sum, int val) {
  if (now == 5) {
    if (can()) {
      if (ok == -1)
        ok = sum;
      else
        ok = min(sum, ok);
    }
    return;
  }
  for (int i = 1; i <= 4; i++) {
    if (i == 1) {
      x[now] = HMM[val * 4 - 4 + now].x1[i];
      y[now] = HMM[val * 4 - 4 + now].y1[i];
      DYGANDQYM(now + 1, sum, val);
    } else {
      x[now] = HMM[val * 4 - 4 + now].x1[i];
      y[now] = HMM[val * 4 - 4 + now].y1[i];
      DYGANDQYM(now + 1, sum + i - 1, val);
    }
  }
}
void init() {
  for (int i = 1; i <= t * 4; i++) {
    scanf("%d%d%d%d", &HMM[i].x1[1], &HMM[i].y1[1], &HMM[i].x2, &HMM[i].y2);
    cal(i);
  }
}
int main() {
  while (~scanf("%d", &t)) {
    init();
    for (int i = 1; i <= t; i++) {
      ok = -1;
      DYGANDQYM(1, 0, i);
      printf("%d\n", ok);
    }
  }
  return 0;
}
