#include <bits/stdc++.h>
using namespace std;
double dist(pair<int, int> p1, pair<int, int> p2) {
  return (sqrt(double(p1.first - p2.first) * (p1.first - p2.first) +
               (p1.second - p2.second) * (p1.second - p2.second)));
}
bool isSquare(pair<int, int> p1, pair<int, int> p2, pair<int, int> p3,
              pair<int, int> p4) {
  double eps = 1e-06;
  double d1 = dist(p1, p2);
  double d2 = dist(p2, p3);
  double d3 = dist(p3, p4);
  double d4 = dist(p4, p1);
  double d5 = dist(p1, p3);
  double d6 = dist(p2, p4);
  if (fabs(d1 - d2) < eps && fabs(d1 - d3) < eps && fabs(d1 - d4) < eps &&
      fabs(d5 - d6) < eps && fabs(d5 * d5 - 2 * d1 * d1) < eps &&
      fabs(d5) >= eps)
    return true;
  if (fabs(d1 - d5) < eps && fabs(d1 - d3) < eps && fabs(d1 - d6) < eps &&
      fabs(d2 - d4) < eps && fabs(d2 * d2 - 2 * d1 * d1) < eps &&
      fabs(d2) >= eps)
    return true;
  if (fabs(d5 - d4) < eps && fabs(d5 - d2) < eps && fabs(d5 - d6) < eps &&
      fabs(d1 - d3) < eps && fabs(d1 * d1 - 2 * d5 * d5) < eps &&
      fabs(d1) >= eps)
    return true;
  return false;
}
struct Surok {
  int x, y, a, b;
  Surok(int x, int y, int a, int b) : x(x), y(y), a(a), b(b) {}
  pair<int, int> Rotate(int k) {
    pair<int, int> ans = make_pair(x, y);
    for (int i = 0; i < k; ++i) {
      ans.first -= a;
      ans.second -= b;
      int t = ans.first;
      ans.first = -ans.second;
      ans.second = t;
      ans.first += a;
      ans.second += b;
    }
    return ans;
  }
};
int main(int argc, char* argv[]) {
  int n;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    vector<Surok> sur;
    for (int j = 0; j < 4; ++j) {
      int x, y, a, b;
      cin >> x >> y >> a >> b;
      sur.push_back(Surok(x, y, a, b));
    }
    int ans = 50;
    for (int j = 0; j < 256; ++j) {
      int curr = 0;
      int l = j;
      vector<int> r;
      while (l) {
        curr += l % 4;
        r.push_back(l % 4);
        l /= 4;
      }
      r.resize(4);
      if (isSquare(sur[0].Rotate(r[0]), sur[1].Rotate(r[1]),
                   sur[2].Rotate(r[2]), sur[3].Rotate(r[3])) &&
          curr < ans)
        ans = curr;
    }
    if (ans == 50)
      cout << -1 << endl;
    else
      cout << ans << endl;
  }
  return 0;
}
