#include <bits/stdc++.h>
using namespace std;
const int maxn = (int)1e5 + 10;
;
int t[4];
int ans;
struct point {
  double x, y;
} pt[4], ct[4];
bool eq(double a, double b) { return abs(a - b) < 1e-6; }
double dist(point a, point b) {
  return sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y));
}
void rotate(point& a, point c) {
  a.x -= c.x;
  a.y -= c.y;
  swap(a.x, a.y);
  a.x *= -1;
  a.x += c.x;
  a.y += c.y;
}
void dfs(int v) {
  if (v == 4) {
    vector<double> dst;
    for (int i = 0; i < 4; i++)
      for (int j = i + 1; j < 4; j++) dst.push_back(dist(pt[i], pt[j]));
    sort(dst.begin(), dst.end());
    double side = dst[0];
    if (eq(side, 0)) return;
    for (int i = 0; i < 4; i++)
      if (!eq(dst[i], side)) return;
    for (int i = 4; i < 6; i++)
      if (!eq(dst[i], side * sqrt(2))) return;
    int b = 0;
    for (int i = 0; i < 4; i++) b += t[i];
    ans = min(ans, b);
  } else {
    t[v] = 0;
    for (int i = 0; i < 4; i++) {
      dfs(v + 1);
      t[v]++;
      rotate(pt[v], ct[v]);
    }
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  while (n--) {
    ans = 50;
    for (int i = 0; i < 4; i++) {
      cin >> pt[i].x >> pt[i].y >> ct[i].x >> ct[i].y;
    }
    dfs(0);
    cout << (ans == 50 ? -1 : ans) << endl;
  }
}
