#include <bits/stdc++.h>
using namespace std;
pair<int, int> p[4];
pair<int, int> r[4];
bool f1() {
  set<pair<int, int> > t;
  for (int i = 0; i < 4; i++) {
    if (t.count(p[i]) != 0) return 0;
    t.insert(p[i]);
  }
  set<long long> dis;
  for (int i = 0; i < 4; i++) {
    for (int j = i + 1; j < 4; j++) {
      dis.insert(
          (long long)(p[i].first - p[j].first) * (p[i].first - p[j].first) +
          (long long)(p[i].second - p[j].second) * (p[i].second - p[j].second));
    }
  }
  return dis.size() <= 2;
}
pair<int, int> rot(pair<int, int> t, int i) {
  int c = 0;
  int s = 1;
  t.first -= r[i].first;
  t.second -= r[i].second;
  pair<int, int> res;
  res.first = c * t.first - s * t.second;
  res.second = s * t.first + c * t.second;
  res.first += r[i].first;
  res.second += r[i].second;
  return res;
}
int f(int i) {
  if (i == 4) {
    if (f1()) return 0;
    return 10000000;
  }
  int r = 1000000;
  r = f(i + 1);
  for (int j = 1; j <= 3; j++) {
    p[i] = rot(p[i], i);
    r = min(r, j + f(i + 1));
  }
  p[i] = rot(p[i], i);
  return r;
}
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 4; j++) {
      cin >> p[j].first >> p[j].second;
      cin >> r[j].first >> r[j].second;
    }
    int res = f(0);
    if (res == 10000000) res = -1;
    cout << res << endl;
  }
  return 0;
}
