#include <bits/stdc++.h>
using namespace std;
pair<int, int> rot(pair<int, int> p, const pair<int, int> &c, const int cnt) {
  for (int i = 0; i < cnt; ++i) {
    pair<int, int> v(p.first - c.first, p.second - c.second);
    p.first = -v.second + c.first;
    p.second = v.first + c.second;
  }
  return p;
}
long long distance(const pair<int, int> &a, const pair<int, int> &b) {
  long long first = a.first - b.first, second = a.second - b.second;
  return first * first + second * second;
}
pair<int, int> make_vector(const pair<int, int> &a, const pair<int, int> &b) {
  return make_pair(b.first - a.first, b.second - a.second);
}
int dot(const pair<int, int> &a, const pair<int, int> &b) {
  return a.first * b.first + a.second * b.second;
}
int cross(const pair<int, int> &a, const pair<int, int> &b) {
  return a.first * b.second - b.first * a.second;
}
inline int mod(int first, const int m) { return (first % m + m) % m; }
bool isConvex(const vector<pair<int, int> > &v) {
  bool pos = false, neg = false;
  for (int i = 1; i < 4; ++i) {
    pair<int, int> v1 = make_vector(v[mod(i - 1, 4)], v[i]);
    pair<int, int> v2 = make_vector(v[i], v[(i + 1) % 4]);
    long long c = cross(v1, v2);
    if (c < 0) neg = true;
    if (c > 0) pos = true;
  }
  return !(pos && neg);
}
bool isSquare(vector<pair<int, int> > &v) {
  sort(v.begin(), v.end());
  do {
    bool yes = isConvex(v);
    if (dot(make_vector(v[0], v[1]), make_vector(v[1], v[2]))) yes = 0;
    long long dist = distance(v[0], v[1]);
    for (int i = 0; i < v.size(); ++i) {
      if (dist != distance(v[i], v[(i + 1) % 4])) yes = 0;
    }
    yes &= (v[0] != v[1] && v[0] != v[2] && v[0] != v[3]);
    if (yes) return true;
  } while (next_permutation(v.begin(), v.end()));
  return false;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int tt;
  cin >> tt;
  while (tt--) {
    vector<pair<int, int> > p(4), home(4);
    for (int i = 0; i < 4; ++i) {
      cin >> p[i].first >> p[i].second >> home[i].first >> home[i].second;
    }
    int ans = -1;
    for (int i = 0; i < 4; ++i) {
      for (int j = 0; j < 4; ++j) {
        for (int k = 0; k < 4; ++k) {
          for (int m = 0; m < 4; ++m) {
            vector<pair<int, int> > temp_p(4);
            vector<int> vv{i, j, k, m};
            for (int l = 0; l < 4; ++l) {
              temp_p[l] = rot(p[l], home[l], vv[l]);
            }
            if (isSquare(temp_p)) {
              if (ans == -1)
                ans = i + j + k + m;
              else
                ans = min(ans, i + j + k + m);
            }
          }
        }
      }
    }
    cout << ans << '\n';
  }
  return 0;
}
