Captain Marmot wants to prepare a huge and important battle against his enemy, Captain Snake. For this battle he has n regiments, each consisting of 4 moles.

Initially, each mole i (1 ≤ i ≤ 4n) is placed at some position (xi, yi) in the Cartesian plane. Captain Marmot wants to move some moles to make the regiments compact, if it's possible.

Each mole i has a home placed at the position (ai, bi). Moving this mole one time means rotating his position point (xi, yi) 90 degrees counter-clockwise around it's home point (ai, bi).

A regiment is compact only if the position points of the 4 moles form a square with non-zero area.

Help Captain Marmot to find out for each regiment the minimal number of moves required to make that regiment compact, if it's possible.

Input

The first line contains one integer n (1 ≤ n ≤ 100), the number of regiments.

The next 4n lines contain 4 integers xi, yi, ai, bi ( - 104 ≤ xi, yi, ai, bi ≤ 104).

Output

Print n lines to the standard output. If the regiment i can be made compact, the i-th line should contain one integer, the minimal number of required moves. Otherwise, on the i-th line print "-1" (without quotes).

Examples

Input

4
1 1 0 0
-1 1 0 0
-1 1 0 0
1 -1 0 0
1 1 0 0
-2 1 0 0
-1 1 0 0
1 -1 0 0
1 1 0 0
-1 1 0 0
-1 1 0 0
-1 1 0 0
2 2 0 1
-1 0 0 -2
3 0 0 -2
-1 1 -2 0


Output

1
-1
3
3

Note

In the first regiment we can move once the second or the third mole.

We can't make the second regiment compact.

In the third regiment, from the last 3 moles we can move once one and twice another one.

In the fourth regiment, we can move twice the first mole and once the third mole.
#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;
}
