#include <bits/stdc++.h>
using namespace std;
int X[] = {1, 0, -1, 0, 1, -1, -1, 1};
int Y[] = {0, 1, 0, -1, 1, 1, -1, -1};
void MN(long long int &a, long long int b) {
  if (a > b) a = b;
}
void MX(long long int &a, long long int b) {
  if (a < b) a = b;
}
void MN(int &a, int b) {
  if (a > b) a = b;
}
void MX(int &a, int b) {
  if (a < b) a = b;
}
long long int MOD(long long int a, long long int b) {
  return a >= 0 ? a % b : (b - abs(a % b)) % b;
}
int OneD(int row, int col, int t_n_o_r) { return row * t_n_o_r + col; }
struct Point {
  int x, y;
};
bool eq(Point p1, Point p2) {
  if (p1.x == p2.x && p1.y == p2.y) return true;
  return false;
}
void r(Point &printf, Point r) {
  Point P_ = printf;
  printf.x = r.x + r.y - P_.y;
  printf.y = P_.x - r.x + r.y;
}
int sqdist(Point p1, Point p2) {
  return (p2.x - p1.x) * (p2.x - p1.x) + (p2.y - p1.y) * (p2.y - p1.y);
}
int issq(Point p1, Point p2, Point p3, Point p4) {
  if (eq(p1, p2) || eq(p1, p3) || eq(p1, p4)) return 0;
  if (eq(p2, p3) || eq(p2, p4)) return 0;
  if (eq(p3, p4)) return 0;
  int d12 = sqdist(p1, p2), d13 = sqdist(p1, p3), d14 = sqdist(p1, p4);
  if (d12 == d13 && d14 == 2 * d12) {
    int d = sqdist(p4, p2);
    if (d == sqdist(p4, p3) && d == d12) return 1;
  }
  if (d12 == d14 && d13 == 2 * d12) {
    int d = sqdist(p3, p2);
    if (d == sqdist(p3, p4) && d == d12) return 1;
  }
  if (d13 == d14 && d12 == 2 * d13) {
    int d = sqdist(p2, p3);
    if (d == sqdist(p2, p4) && d == d13) return 1;
  }
  return 0;
}
int main() {
  int n;
  scanf("%d", &n);
  for (int I = 0; I < n; I++) {
    vector<Point> dot(4), home(4);
    int res = 1e9;
    for (int ii = 0; ii < 4; ii++)
      scanf("%d%d%d%d", &dot[ii].x, &dot[ii].y, &home[ii].x, &home[ii].y);
    for (int i = 0; i < 4; i++) {
      for (int ii = 0; ii < 4; ii++) {
        for (int iii = 0; iii < 4; iii++) {
          for (int iiii = 0; iiii < 4; iiii++) {
            if (issq(dot[0], dot[1], dot[2], dot[3])) {
              MN(res, i + ii + iii + iiii);
            }
            r(dot[3], home[3]);
          }
          r(dot[2], home[2]);
        }
        r(dot[1], home[1]);
      }
      r(dot[0], home[0]);
    }
    if (res == 1e9)
      printf("-1\n");
    else
      printf("%d\n", res);
  }
  return 0;
}
