#include <bits/stdc++.h>
using namespace std;
struct point {
  int x, y;
  point() { x = y = 0; }
  point(int _x, int _y) : x(_x), y(_y){};
};
point home[4], pos[4];
point rotate(point p, point home) {
  int s = 1, c = 0;
  p.x -= home.x;
  p.y -= home.y;
  point now;
  now.x = p.x * c - p.y * s;
  now.y = p.x * s + p.y * c;
  p.x = now.x + home.x;
  p.y = now.y + home.y;
  return point(p);
}
long long dist(point p1, point p2) {
  return (p1.x - p2.x) * (p1.x - p2.x) + (p1.y - p2.y) * (p1.y - p2.y);
}
bool is_Square(point k1, point k2, point k3, point k4) {
  set<long long> my;
  my.insert(dist(k1, k2));
  my.insert(dist(k1, k3));
  my.insert(dist(k1, k4));
  my.insert(dist(k2, k3));
  my.insert(dist(k2, k4));
  my.insert(dist(k3, k4));
  set<long long>::iterator it = my.begin();
  long long t = *it;
  it++;
  if ((int)my.size() <= 2 && t && *it) return 1;
  return 0;
}
void can() {
  point r1 = pos[0], r2 = pos[1], r3 = pos[2], r4 = pos[3];
  int mn = 1000;
  for (int i = 0; i < 4; i++) {
    for (int j = 0; j < 4; j++) {
      for (int l = 0; l < 4; l++) {
        for (int k = 0; k < 4; k++) {
          if (is_Square(r1, r2, r3, r4)) mn = min(mn, i + j + l + k);
          r4 = rotate(r4, home[3]);
        }
        r3 = rotate(r3, home[2]);
      }
      r2 = rotate(r2, home[1]);
    }
    r1 = rotate(r1, home[0]);
  }
  cout << (mn == 1000 ? -1 : mn) << endl;
}
int main() {
  int n;
  cin >> n;
  for (int j = 0; j < n; j++) {
    for (int i = 0; i < 4; i++) {
      int x, y, a, b;
      cin >> x >> y >> a >> b;
      home[i] = point(a, b);
      pos[i] = point(x, y);
    }
    can();
  }
  return 0;
}
