#include <bits/stdc++.h>
using namespace std;
const int maxn = 1111111;
const int mod = (int)(1e9 + 7);
const int INF = 0x7f7f7f7f;
struct Rec {
  long long a, b, dx, dy;
  Rec() {}
  void read() {
    cin >> dx >> dy >> a >> b;
    dx -= a;
    dy -= b;
  }
  Rec(int a, int b, int x, int y) {
    dx = x - a;
    dy = y - b;
    this->a = a;
    this->b = b;
  }
  void Rotate() {
    swap(dx, dy);
    dx = -dx;
  }
  long long x() { return a + dx; }
  long long y() { return b + dy; }
} r[4];
struct Point {
  long long x, y;
  long long len() const { return x * x + y * y; }
  Point() {}
  Point(long long x, long long y) : x(x), y(y) {}
  bool operator<(const Point& tmp) const { return this->len() < tmp.len(); }
  Point operator-(const Point& tmp) const {
    return Point(x - tmp.x, y - tmp.y);
  }
} p[5], q[5], v[5];
long long dot(Point a, Point b) { return a.x * b.x + a.y * b.y; }
bool check() {
  long long s = 0;
  for (int i = 0; i < 4; ++i) {
    p[i].x = r[i].x();
    p[i].y = r[i].y();
    for (int j = 0; j < i; ++j) {
      if (p[j].x == p[i].x && p[i].y == p[j].y) return false;
    }
  }
  for (int i = 0; i < 3; ++i) {
    v[i] = p[i + 1] - p[0];
    if (v[i].len() == 0) return false;
  }
  sort(v, v + 3);
  s = dot(v[0], v[1]);
  if (s != 0) {
    return false;
  }
  s = dot(v[0], v[2]);
  if (s <= 0) {
    return false;
  }
  s = dot(v[1], v[2]);
  if (s <= 0) {
    return false;
  }
  if (v[0].len() != v[1].len()) return false;
  if (v[0].len() * 2 == v[2].len()) {
    return true;
  }
  return false;
}
int ans;
void dfs(int dep, int cnt) {
  if (dep >= 4) {
    if (check()) {
      ans = min(ans, cnt);
    }
    return;
  }
  for (int i = 0; i < 4; ++i) {
    dfs(dep + 1, cnt + i);
    r[dep].Rotate();
  }
}
int main() {
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  while (n--) {
    for (int i = 0; i < 4; ++i) {
      r[i].read();
    }
    ans = INF;
    dfs(0, 0);
    if (ans == INF) ans = -1;
    cout << ans << endl;
  }
  return 0;
}
