#include <bits/stdc++.h>
#pragma comment(linker, "/stack:32000000")
using namespace std;
long long n, m, k, d, w;
vector<long long> v;
vector<int> rmq;
long long gcd(long long a, long long b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
long long combine(long long a, long long b) {
  if (a < b) swap(a, b);
  return gcd(a, b);
}
long long get_gcd(int ver, int v_l, int v_r, int l, int r) {
  if (l == v_l && r == v_r) return rmq[ver];
  int mid = (v_l + v_r) / 2;
  if (l > mid)
    return get_gcd(ver * 2 + 1, mid + 1, v_r, l, r);
  else if (r <= mid)
    return get_gcd(ver * 2, v_l, mid, l, r);
  else
    return combine(get_gcd(ver * 2, v_l, mid, l, mid),
                   get_gcd(ver * 2 + 1, mid + 1, v_r, mid + 1, r));
}
void build(int ver, int v_l, int v_r) {
  if (v_l == v_r)
    rmq[ver] = v[v_l];
  else {
    int mid = (v_l + v_r) / 2;
    build(ver * 2, v_l, mid);
    build(ver * 2 + 1, mid + 1, v_r);
    rmq[ver] = combine(rmq[ver * 2], rmq[ver * 2 + 1]);
  }
}
long long bin_s(int start, long long need) {
  int l = start - 1;
  int r = n;
  while (r - l > 1) {
    int mid = (l + r) / 2;
    if (get_gcd(0, 0, n - 1, start, mid) > need) {
      r = mid;
    } else {
      l = mid;
    }
  }
  int l2 = start - 1;
  int r2 = n;
  while (r2 - l2 > 1) {
    int mid = (l2 + r2) / 2;
    if (get_gcd(0, 0, n - 1, start, mid) >= need) {
      r2 = mid;
    } else {
      l2 = mid;
    }
  }
  int cnt = l - r2 + 1;
  return cnt;
}
struct tt {
  pair<int, int> pos;
  pair<int, int> ankor;
};
tt rotate(tt p) {
  int x = p.pos.first;
  int y = p.pos.second;
  int r_x = p.ankor.first;
  int r_y = p.ankor.second;
  x -= r_x;
  y -= r_y;
  tt a = p;
  pair<int, int> rot_0 = (make_pair(-y + r_x, x + r_y));
  a.pos = rot_0;
  return a;
}
double dst(pair<int, int> p1, pair<int, int> p2) {
  return pow((double)(p1.first - p2.first), 2) +
         pow((double)(p1.second - p2.second), 2);
}
bool check(vector<pair<int, int> >& v) {
  sort(v.begin(), v.end());
  set<pair<int, int> > test(v.begin(), v.end());
  if (test.size() < 4) return false;
  if (v[0].first == v[1].first && v[2].first == v[3].first) {
    if (v[0].second == v[2].second && v[1].second == v[3].second) {
      if (abs(v[1].second - v[0].second) == abs(v[2].first - v[0].first))
        return true;
    }
  } else {
    double len = dst(v[0], v[1]);
    if (len == dst(v[1], v[3]) && len == dst(v[3], v[2]) &&
        len == dst(v[2], v[0])) {
      if (dst(v[1], v[2]) == dst(v[0], v[3])) return true;
    }
  }
  return false;
}
int main() {
  cin >> n;
  vector<tt> v(4 * n);
  for (int i = 0; i < 4 * n; i++) {
    int x, y, a, b;
    cin >> x >> y >> a >> b;
    tt n_tt;
    n_tt.pos = (make_pair(x, y));
    n_tt.ankor = (make_pair(a, b));
    v[i] = n_tt;
  }
  for (int i = 0; i < n; i++) {
    int mask[4] = {0};
    int rotate_cnt = (int)1e9;
    for (int j = 0; j <= 256; j++) {
      vector<tt> temp(4);
      int t_rotate_cnt = 0;
      for (int k = 0; k < 4; k++) temp[k] = v[i * 4 + k];
      for (int k = 0; k < 4; k++) {
        t_rotate_cnt += mask[k];
        for (int cnt = 0; cnt < mask[k]; cnt++) temp[k] = rotate(temp[k]);
      }
      vector<pair<int, int> > poss(4);
      for (int k = 0; k < 4; k++) poss[k] = temp[k].pos;
      if (check(poss)) {
        rotate_cnt = min(rotate_cnt, t_rotate_cnt);
      }
      int ind = 3;
      mask[ind]++;
      while (mask[ind] > 3) {
        mask[ind] = 0;
        ind--;
        if (ind >= 0) mask[ind]++;
      }
    }
    if (rotate_cnt == (int)1e9)
      cout << -1 << endl;
    else
      cout << rotate_cnt << endl;
  }
  return 0;
}
