#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:20000000")
using namespace std;
int ri() {
  int x;
  scanf("%d", &x);
  return x;
}
long long rll() {
  long long x;
  scanf("%lld", &x);
  return x;
}
int x[10], y[10];
int a[10], b[10];
pair<int, int> rotate(int xx, int yy, int aa, int bb, int cnt) {
  pair<int, int> res(xx, yy);
  for (int i = 1; i <= cnt; i++) {
    int dx = res.first - aa;
    int dy = res.second - bb;
    int ndx = -dy;
    int ndy = dx;
    res.first = aa + ndx;
    res.second = bb + ndy;
  }
  return res;
}
bool check_square(vector<pair<int, int> > &mas) {
  set<pair<int, int> > st;
  for (int i = 0; i < mas.size(); i++) st.insert(mas[i]);
  if (st.size() != 4) return false;
  map<long long, int> dist;
  for (int i = 0; i < mas.size(); i++)
    for (int j = i + 1; j < mas.size(); j++) {
      long long d = (long long)(mas[j].first - mas[i].first) *
                        (long long)(mas[j].first - mas[i].first) +
                    (long long)(mas[j].second - mas[i].second) *
                        (long long)(mas[j].second - mas[i].second);
      dist[d]++;
    }
  return dist.size() == 2 && dist.begin()->second == 4 &&
         dist.begin()->first * 2 == (++dist.begin())->first;
}
void solve() {
  int n = ri();
  for (int i = (int)(1); i <= (int)(n); i++) {
    for (int j = (int)(1); j <= (int)(4); j++)
      cin >> x[j] >> y[j] >> a[j] >> b[j];
    int res = 100500;
    for (int a1 = (int)(0); a1 <= (int)(3); a1++)
      for (int a2 = (int)(0); a2 <= (int)(3); a2++)
        for (int a3 = (int)(0); a3 <= (int)(3); a3++)
          for (int a4 = (int)(0); a4 <= (int)(3); a4++) {
            vector<pair<int, int> > temp;
            temp.push_back(rotate(x[1], y[1], a[1], b[1], a1));
            temp.push_back(rotate(x[2], y[2], a[2], b[2], a2));
            temp.push_back(rotate(x[3], y[3], a[3], b[3], a3));
            temp.push_back(rotate(x[4], y[4], a[4], b[4], a4));
            sort(temp.begin(), temp.end());
            if (check_square(temp)) res = min(res, a1 + a2 + a3 + a4);
          }
    if (res == 100500)
      cout << -1 << endl;
    else
      cout << res << endl;
  }
}
int main() {
  solve();
  return 0;
}
