#include <bits/stdc++.h>
using namespace std;
int ed(pair<int, int> a, pair<int, int> b) {
  return (a.first - b.first) * (a.first - b.first) +
         (a.second - b.second) * (a.second - b.second);
}
bool eq(pair<int, int> a, pair<int, int> b) {
  return a.first == b.first && a.second == b.second;
}
bool issquare(pair<int, int> a, pair<int, int> b, pair<int, int> c,
              pair<int, int> d) {
  int d2 = ed(a, b);
  int d3 = ed(a, c);
  int d4 = ed(a, d);
  if (d2 == 0 || d3 == 0 || d4 == 0) return false;
  if (d2 == d3 && 2 * d2 == d4 && 2 * ed(b, d) == ed(b, c)) {
    return true;
  }
  if (d3 == d4 && 2 * d3 == d2 && 2 * ed(c, b) == ed(c, d)) {
    return true;
  }
  if (d2 == d4 && 2 * d2 == d3 && 2 * ed(b, c) == ed(b, d)) {
    return true;
  }
  return false;
}
void solve() {
  int n;
  cin >> n;
  const int m = 4;
  for (int q = 0; q < n; q++) {
    int min1 = 100;
    pair<int, int> _1[4], _2[4], _3[4], _4[4];
    int a1, b1;
    cin >> _1[0].first >> _1[0].second >> a1 >> b1;
    int a2, b2;
    cin >> _2[0].first >> _2[0].second >> a2 >> b2;
    int a3, b3;
    cin >> _3[0].first >> _3[0].second >> a3 >> b3;
    int a4, b4;
    cin >> _4[0].first >> _4[0].second >> a4 >> b4;
    for (int i = 1; i < 4; i++) {
      _1[i].first = a1 + b1 - _1[i - 1].second;
      _1[i].second = b1 - a1 + _1[i - 1].first;
      _2[i].first = a2 + b2 - _2[i - 1].second;
      _2[i].second = b2 - a2 + _2[i - 1].first;
      _3[i].first = a3 + b3 - _3[i - 1].second;
      _3[i].second = b3 - a3 + _3[i - 1].first;
      _4[i].first = a4 + b4 - _4[i - 1].second;
      _4[i].second = b4 - a4 + _4[i - 1].first;
    }
    for (int a = 0; a < 4; a++) {
      for (int b = 0; b < 4; b++) {
        for (int c = 0; c < 4; c++) {
          for (int d = 0; d < 4; d++) {
            if (issquare(_1[a], _2[b], _3[c], _4[d]))
              min1 = min(a + b + c + d, min1);
          }
        }
      }
    }
    if (min1 == 100)
      cout << -1 << "\n";
    else
      cout << min1 << "\n";
  }
}
int main() {
  {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
  }
  long long t;
  t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
