#include <bits/stdc++.h>
using namespace std;
void fast_in_out() {
  std::ios_base::sync_with_stdio(NULL);
  cin.tie(NULL);
  cout.tie(NULL);
}
int dx[] = {0, 0, -1, 1, -1, 1, -1, 1, 0};
int dy[] = {-1, 1, 0, 0, -1, -1, 1, 1, 0};
int lx[] = {2, 2, -1, 1, -2, -2, -1, 1};
int ly[] = {-1, 1, 2, 2, 1, -1, -2, -2};
const long double eps = 1e-9;
const int N = 1e3 + 50, M = 1e5 + 10, mod = 1e9 + 7;
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
long long lcm(long long a, long long b) {
  long long t = gcd(a, b);
  return t ? (a / t * b) : 0;
}
struct p {
  int x, y;
};
long long dis(p a, p b) {
  int x = a.x - b.x;
  int y = a.y - b.y;
  return x * x + y * y;
}
bool check(vector<p> v) {
  p a, b, c, d;
  vector<int> ind{0, 1, 2, 3};
  for (int i = 0; i < 4; i++)
    for (int j = i + 1; j < 4; j++)
      if (v[i].x == v[j].x && v[i].y == v[j].y) return 0;
  do {
    a = v[ind[0]], b = v[ind[1]], c = v[ind[2]], d = v[ind[3]];
    bool ok = dis(a, b) == dis(b, c);
    ok &= (dis(a, b) == dis(c, d));
    ok &= (dis(a, b) == dis(d, a));
    ok &= (dis(a, c) == dis(b, d));
    if (ok) return 1;
  } while (next_permutation(ind.begin(), ind.end()));
  return 0;
}
int ans = 1000;
p rotate(p a, p b) {
  a.x -= b.x;
  a.y -= b.y;
  swap(a.x, a.y);
  a.x *= -1;
  a.x += b.x;
  a.y += b.y;
  return a;
}
void solve(int ind, pair<vector<p>, vector<p>> v, int cost) {
  if (ind == 4) {
    if (check(v.second)) ans = min(ans, cost);
    return;
  }
  p a = v.second[ind];
  p b = v.first[ind];
  solve(ind + 1, v, cost);
  a = rotate(a, b);
  v.second[ind] = a;
  solve(ind + 1, v, cost + 1);
  a = rotate(a, b);
  v.second[ind] = a;
  solve(ind + 1, v, cost + 2);
  a = rotate(a, b);
  v.second[ind] = a;
  solve(ind + 1, v, cost + 3);
  return;
}
int main() {
  fast_in_out();
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    pair<vector<p>, vector<p>> v;
    ans = 1000;
    vector<p> v1(4), v2(4);
    for (int j = 0; j < 4; j++) {
      cin >> v2[j].x >> v2[j].y;
      cin >> v1[j].x >> v1[j].y;
    }
    v = {v1, v2};
    solve(0, v, 0);
    if (ans == 1000) ans = -1;
    cout << ans << '\n';
  }
  return 0;
}
