#include <bits/stdc++.h>
using namespace std;
struct node {
  int x1;
  int y1;
  int x2;
  int y2;
} input[4];
pair<double, double> temp[4];
pair<double, double> rotate(double x1, double y1, double x2, double y2) {
  double x = -(y1 - y2) + x2;
  double y = (x1 - x2) + y2;
  return pair<double, double>(x, y);
}
pair<double, double> rotateNTimes(double x1, double y1, double x2, double y2,
                                  int n) {
  for (int i = 0; i < n; i++) {
    pair<double, double> p = rotate(x1, y1, x2, y2);
    x1 = p.first;
    y1 = p.second;
  }
  return pair<double, double>(x1, y1);
}
bool check() {
  int i, j, k, l;
  double x = 0, y = 0;
  for (i = 0; i < 4; i++)
    for (j = i + 1; j < 4; j++) {
      if (temp[i].first == temp[j].first && temp[i].second == temp[j].second)
        return false;
    }
  for (i = 0; i < 4; i++) {
    x = x + temp[i].first;
    y = y + temp[i].second;
  }
  x /= 4;
  y /= 4;
  double dist = (temp[0].first - x) * (temp[0].first - x) +
                (temp[0].second - y) * (temp[0].second - y);
  for (i = 1; i < 4; i++) {
    double d = (temp[i].first - x) * (temp[i].first - x) +
               (temp[i].second - y) * (temp[i].second - y);
    if (dist != d) return false;
  }
  for (i = 0; i < 4; i++)
    for (j = i + 1; j < 4; j++) {
      for (k = 0; k < 4; k++)
        for (l = k + 1; l < 4; l++) {
          if (k != i && k != j && l != i && l != j) {
            double vx1 = (temp[i].first - temp[j].first);
            double vy1 = (temp[i].second - temp[j].second);
            double vx2 = (temp[k].first - temp[l].first);
            double vy2 = (temp[k].second - temp[l].second);
            if (vx1 * vx2 + vy1 * vy2 == 0) return true;
          }
        }
    }
  return false;
}
void dfs(int cur, int n, int tot, int& min) {
  if (cur == n) {
    if (check()) {
      if (min < 0 || tot < min) min = tot;
    }
  } else {
    for (int i = 0; i <= 3; i++) {
      pair<double, double> p = rotateNTimes(input[cur].x1, input[cur].y1,
                                            input[cur].x2, input[cur].y2, i);
      temp[cur] = p;
      dfs(cur + 1, n, tot + i, min);
    }
  }
}
int main() {
  int i, j, n, a, b;
  while (scanf("%d", &n) != EOF) {
    for (i = 0; i < n; i++) {
      for (j = 0; j < 4; j++)
        scanf("%d%d%d%d", &input[j].x1, &input[j].y1, &input[j].x2,
              &input[j].y2);
      int min = -1;
      dfs(0, 4, 0, min);
      printf("%d\n", min);
    }
  }
  return 0;
}
