#include <bits/stdc++.h>
using namespace std;
struct debugger {
  template <typename T>
  debugger &operator,(const T &v) {
    cerr << v << "\t";
    return *this;
  }
} dbg;
template <class T, class U>
inline T max(T &a, U &b) {
  return a > b ? a : b;
}
template <class T, class U>
inline T min(T &a, U &b) {
  return a < b ? a : b;
}
template <class T, class U>
inline T swap(T &a, U &b) {
  T tmp = a;
  a = b;
  b = tmp;
}
const int INF = 1 << 30;
const int mx = 1e5 + 7;
const int mod = 1000000007;
const double pi = 2 * acos(0.0);
int EQ(double d) {
  if (fabs(d) < 1e-7) return 0;
  return d > 1e-7 ? 1 : -1;
}
pair<long long, long long> p[5], pp[5];
vector<pair<long long, long long> > v[5];
bool parallel(pair<long long, long long> a, pair<long long, long long> b,
              pair<long long, long long> c, pair<long long, long long> d) {
  pair<long long, long long> e =
      pair<long long, long long>(b.first - a.first, b.second - a.second);
  pair<long long, long long> f =
      pair<long long, long long>(d.first - c.first, d.second - c.second);
  int tmp = e.first * f.second - e.second * f.first;
  return (tmp == 0);
}
long long dis(pair<long long, long long> a, pair<long long, long long> b) {
  return ((a.first - b.first) * (a.first - b.first) +
          (a.second - b.second) * (a.second - b.second));
}
bool isSqr(int i, int j, int k, int l) {
  pair<long long, long long> a[4];
  a[0] = v[0][i], a[1] = v[1][j], a[2] = v[2][k], a[3] = v[3][l];
  i = 0, j = 1, k = 2, l = 3;
  if (parallel(a[i], a[j], a[k], a[l])) {
    if (parallel(a[i], a[k], a[j], a[l]) &&
        (dis(a[i], a[j]) == dis(a[k], a[l]) &&
         dis(a[i], a[k]) == dis(a[j], a[l]) &&
         dis(a[i], a[j]) == dis(a[j], a[l])) &&
        dis(a[i], a[j]) != 0 &&
        dis(a[i], a[j]) + dis(a[l], a[j]) == dis(a[i], a[l])) {
      return true;
    } else if (parallel(a[i], a[l], a[j], a[k]) &&
               (dis(a[i], a[j]) == dis(a[k], a[l]) &&
                dis(a[i], a[l]) == dis(a[j], a[k]) &&
                dis(a[i], a[j]) == dis(a[j], a[k])) &&
               dis(a[i], a[j]) != 0 &&
               dis(a[i], a[j]) + dis(a[k], a[j]) == dis(a[i], a[k])) {
      return true;
    }
  }
  i = 0, j = 2, k = 1, l = 3;
  if (parallel(a[i], a[j], a[k], a[l])) {
    if (parallel(a[i], a[k], a[j], a[l]) &&
        (dis(a[i], a[j]) == dis(a[k], a[l]) &&
         dis(a[i], a[k]) == dis(a[j], a[l]) &&
         dis(a[i], a[j]) == dis(a[j], a[l])) &&
        dis(a[i], a[j]) != 0 &&
        dis(a[i], a[j]) + dis(a[l], a[j]) == dis(a[i], a[l])) {
      return true;
    } else if (parallel(a[i], a[l], a[j], a[k]) &&
               (dis(a[i], a[j]) == dis(a[k], a[l]) &&
                dis(a[i], a[l]) == dis(a[j], a[k]) &&
                dis(a[i], a[j]) == dis(a[j], a[k])) &&
               dis(a[i], a[j]) != 0 &&
               dis(a[i], a[j]) + dis(a[k], a[j]) == dis(a[i], a[k])) {
      return true;
    }
  }
  i = 0, j = 3, k = 2, l = 1;
  if (parallel(a[i], a[j], a[k], a[l])) {
    if (parallel(a[i], a[k], a[j], a[l]) &&
        (dis(a[i], a[j]) == dis(a[k], a[l]) &&
         dis(a[i], a[k]) == dis(a[j], a[l]) &&
         dis(a[i], a[j]) == dis(a[j], a[l])) &&
        dis(a[i], a[j]) != 0 &&
        dis(a[i], a[j]) + dis(a[l], a[j]) == dis(a[i], a[l])) {
      return true;
    } else if (parallel(a[i], a[l], a[j], a[k]) &&
               (dis(a[i], a[j]) == dis(a[k], a[l]) &&
                dis(a[i], a[l]) == dis(a[j], a[k]) &&
                dis(a[i], a[j]) == dis(a[j], a[k])) &&
               dis(a[i], a[j]) != 0 &&
               dis(a[i], a[j]) + dis(a[k], a[j]) == dis(a[i], a[k])) {
      return true;
    }
  }
  return false;
}
int check() {
  int ans = INF;
  for (__typeof((4) - 1) i = (0); i <= ((4) - 1); ++i) {
    for (__typeof((4) - 1) j = (0); j <= ((4) - 1); ++j) {
      for (__typeof((4) - 1) k = (0); k <= ((4) - 1); ++k) {
        for (__typeof((4) - 1) l = (0); l <= ((4) - 1); ++l) {
          if (isSqr(i, j, k, l)) {
            ans = min(ans, i + j + k + l);
          }
        }
      }
    }
  }
  if (ans == INF) return -1;
  return ans;
}
pair<long long, long long> rotate(pair<long long, long long> p,
                                  pair<long long, long long> a) {
  pair<long long, long long> v =
      pair<long long, long long>(a.first - p.first, a.second - p.second);
  int c = 0, s = 1;
  return pair<long long, long long>(p.first + v.first * c - v.second * s,
                                    p.second + v.first * s + v.second * c);
}
int call() {
  for (__typeof((4) - 1) i = (0); i <= ((4) - 1); ++i) v[i].clear();
  for (__typeof((4) - 1) i = (0); i <= ((4) - 1); ++i) {
    v[i].push_back(p[i]);
    for (__typeof((3) - 1) j = (0); j <= ((3) - 1); ++j) {
      v[i].push_back(rotate(pp[i], v[i][j]));
    }
  }
  return check();
}
int main() {
  int n = ({
    int a;
    scanf("%d", &a);
    a;
  });
  for (__typeof((n)-1) i = (0); i <= ((n)-1); ++i) {
    for (__typeof((4) - 1) j = (0); j <= ((4) - 1); ++j) {
      p[j].first = ({
        int a;
        scanf("%d", &a);
        a;
      }),
      p[j].second = ({
        int a;
        scanf("%d", &a);
        a;
      });
      pp[j].first = ({
        int a;
        scanf("%d", &a);
        a;
      }),
      pp[j].second = ({
        int a;
        scanf("%d", &a);
        a;
      });
    }
    cout << call() << endl;
  }
}
