#include <bits/stdc++.h>
using namespace std;
struct mole {
  int x;
  int y;
  int a;
  int b;
  mole() {}
  mole(int x, int y, int a, int b) : x(x), y(y), a(a), b(b) {}
};
vector<mole> v;
vector<pair<int, int> > aux;
int r;
long long int dist(int i, int j) {
  long long int dx = aux[i].first - aux[j].first;
  long long int dy = aux[i].second - aux[j].second;
  return dx * dx + dy * dy;
}
long long int dot(pair<long long int, long long int> a,
                  pair<long long int, long long int> b) {
  return 1LL * a.first * b.first + 1LL * a.second * b.second;
}
int check(void) {
  vector<pair<long long int, int> > d;
  for (int i = 1; i < 4; i++) {
    d.push_back(make_pair(dist(0, i), i));
  }
  sort(d.begin(), d.end());
  if (d[0].first == 0) {
    return 0;
  }
  if (d[0].first != d[1].first) {
    return 0;
  }
  if (2 * d[1].first != d[2].first) {
    return 0;
  }
  vector<pair<long long int, int> > sq;
  sq.push_back(aux[0]);
  sq.push_back(aux[d[0].second]);
  sq.push_back(aux[d[2].second]);
  sq.push_back(aux[d[1].second]);
  for (int i = 0; i < 4; i++) {
    int x1 = sq[i].first;
    int y1 = sq[i].second;
    int x2 = sq[(i + 1) % 4].first;
    int y2 = sq[(i + 1) % 4].second;
    int x3 = sq[(i + 2) % 4].first;
    int y3 = sq[(i + 2) % 4].second;
    pair<long long int, long long int> a = make_pair(x2 - x1, y2 - y1);
    pair<long long int, long long int> b = make_pair(x3 - x2, y3 - y2);
    if (dot(a, b) != 0) {
      return 0;
    }
  }
  return 1;
}
void solve(int pos, int move) {
  if (pos >= 4) {
    if (check()) {
      r = min(r, move);
    }
    return;
  }
  int a = v[pos].a;
  int b = v[pos].b;
  int x = v[pos].x - a;
  int y = v[pos].y - b;
  aux.push_back(make_pair(x + a, y + b));
  solve(pos + 1, move);
  aux.pop_back();
  aux.push_back(make_pair(-y + a, x + b));
  solve(pos + 1, move + 1);
  aux.pop_back();
  aux.push_back(make_pair(-x + a, -y + b));
  solve(pos + 1, move + 2);
  aux.pop_back();
  aux.push_back(make_pair(y + a, -x + b));
  solve(pos + 1, move + 3);
  aux.pop_back();
  return;
}
int main(void) {
  int n;
  int x, y, a, b;
  scanf(" %d", &n);
  while (n--) {
    v.clear();
    aux.clear();
    for (int i = 0; i < 4; i++) {
      scanf(" %d %d %d %d", &x, &y, &a, &b);
      v.push_back(mole(x, y, a, b));
    }
    r = 0x3f3f3f3f;
    solve(0, 0);
    if (r < 0x3f3f3f3f) {
      printf("%d\n", r);
    } else {
      printf("-1\n");
    }
  }
  return 0;
}
