#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:16777216")
using namespace std;
const double pi = acos(-1.0);
const int INF = 1000000007;
struct kroty {
  int x, y, a, b;
};
int n;
template <typename T>
inline void MustDie(T tmp) {
  cout << tmp;
  exit(0);
}
inline bool is_sqr(vector<kroty> &t) {
  vector<long long> p;
  for (int i = 0; i < (int)4; ++i)
    for (int j = i + 1; j < 4; ++j)
      p.push_back((long long)(t[i].x - t[j].x) * (t[i].x - t[j].x) +
                  (long long)(t[i].y - t[j].y) * (t[i].y - t[j].y));
  sort(p.begin(), p.end());
  return (p[0] == p[3] && p[4] == p[5] && p[4] == 2 * p[0] &&
          !count(p.begin(), p.end(), 0));
}
int main() {
  ios_base::sync_with_stdio(0);
  cin >> n;
  for (int l = 0; l < (int)n; ++l) {
    int ans = INF;
    vector<kroty> a(4);
    for (int i = 0; i < (int)4; ++i)
      cin >> a[i].x >> a[i].y >> a[i].a >> a[i].b;
    for (int i1 = 0; i1 < (int)4; ++i1) {
      for (int i2 = 0; i2 < (int)4; ++i2) {
        for (int i3 = 0; i3 < (int)4; ++i3) {
          for (int i4 = 0; i4 < (int)4; ++i4) {
            if (is_sqr(a) && i1 + i2 + i3 + i4 < ans) ans = i1 + i2 + i3 + i4;
            int xt = a[3].x - a[3].a, yt = a[3].y - a[3].b;
            a[3].x = a[3].a - yt;
            a[3].y = a[3].b + xt;
          }
          int xt = a[2].x - a[2].a, yt = a[2].y - a[2].b;
          a[2].x = a[2].a - yt;
          a[2].y = a[2].b + xt;
        }
        int xt = a[1].x - a[1].a, yt = a[1].y - a[1].b;
        a[1].x = a[1].a - yt;
        a[1].y = a[1].b + xt;
      }
      int xt = a[0].x - a[0].a, yt = a[0].y - a[0].b;
      a[0].x = a[0].a - yt;
      a[0].y = a[0].b + xt;
    }
    ans == INF ? cout << -1 : cout << ans;
    cout << endl;
  }
  exit(0);
}
