#include <bits/stdc++.h>
using namespace std;
struct node {
  long long x, y;
} sa1[20], sa2[20];
vector<node> ch[10];
long long getdis(node aa, node bb) {
  long long tmp = (aa.x - bb.x) * (aa.x - bb.x) + (aa.y - bb.y) * (aa.y - bb.y);
  return tmp;
}
bool cmp(long long aa, long long bb) { return aa < bb; }
bool check(int p1, int p2, int p3, int p4) {
  vector<node> tmp;
  vector<long long> dis;
  tmp.push_back(ch[1][p1]);
  tmp.push_back(ch[2][p2]);
  tmp.push_back(ch[3][p3]);
  tmp.push_back(ch[4][p4]);
  for (int i = 0; i < 4; i++) {
    for (int j = i + 1; j < 4; j++) {
      dis.push_back(getdis(tmp[i], tmp[j]));
    }
  }
  sort(dis.begin(), dis.end(), cmp);
  if (dis[0] == 0) {
    return false;
  }
  if (dis[0] != dis[3]) {
    return false;
  }
  if (dis[4] != dis[5]) {
    return false;
  }
  return true;
}
void solve() {
  int ans = 100000;
  for (int i = 0; i <= 3; i++) {
    for (int j = 0; j <= 3; j++) {
      for (int k = 0; k <= 3; k++) {
        for (int t = 0; t <= 3; t++) {
          if (check(i, j, k, t)) {
            ans = min(ans, i + j + k + t);
          }
        }
      }
    }
  }
  if (ans != 100000) {
    printf("%d\n", ans);
  } else {
    printf("-1\n");
  }
}
node rot(node now, int num) {
  long long xx = now.y - sa2[num].y;
  long long yy = now.x - sa2[num].x;
  node tmp;
  tmp.x = sa2[num].x - xx;
  tmp.y = sa2[num].y + yy;
  return tmp;
}
void init() {
  for (int i = 1; i <= 4; i++) {
    ch[i].clear();
  }
  for (int i = 1; i <= 4; i++) {
    ch[i].push_back(sa1[i]);
    for (int j = 1; j <= 3; j++) {
      ch[i].push_back(rot(ch[i][j - 1], i));
    }
  }
}
int main() {
  int cas;
  scanf("%d", &cas);
  while (cas--) {
    for (int i = 1; i <= 4; i++) {
      scanf("%I64d%I64d", &sa1[i].x, &sa1[i].y);
      scanf("%I64d%I64d", &sa2[i].x, &sa2[i].y);
    }
    init();
    solve();
  }
  return 0;
}
