#include <bits/stdc++.h>
using namespace std;
void __print(int first) { cerr << first; }
void __print(long first) { cerr << first; }
void __print(long long first) { cerr << first; }
void __print(unsigned first) { cerr << first; }
void __print(unsigned long first) { cerr << first; }
void __print(unsigned long long first) { cerr << first; }
void __print(float first) { cerr << first; }
void __print(double first) { cerr << first; }
void __print(long double first) { cerr << first; }
void __print(char first) { cerr << '\'' << first << '\''; }
void __print(const char *first) { cerr << '\"' << first << '\"'; }
void __print(const string &first) { cerr << '\"' << first << '\"'; }
void __print(bool first) { cerr << (first ? "true" : "false"); }
template <typename T, typename V>
void __print(const pair<T, V> &first) {
  cerr << '{';
  __print(first.first);
  cerr << ',';
  __print(first.second);
  cerr << '}';
}
template <typename T>
void __print(const T &first) {
  int f = 0;
  cerr << '{';
  for (auto &i : first) cerr << (f++ ? "," : ""), __print(i);
  cerr << "}";
}
void _print() { cerr << "]\n"; }
template <typename T, typename... V>
void _print(T t, V... v) {
  __print(t);
  if (sizeof...(v)) cerr << ", ";
  _print(v...);
}
pair<long long, long long> root[5], point[5][4];
long long distSq(pair<long long, long long> p, pair<long long, long long> q) {
  return (p.first - q.first) * (p.first - q.first) +
         (p.second - q.second) * (p.second - q.second);
}
bool isSquare(pair<long long, long long> p1, pair<long long, long long> p2,
              pair<long long, long long> p3, pair<long long, long long> p4) {
  long long d2 = distSq(p1, p2);
  long long d3 = distSq(p1, p3);
  long long d4 = distSq(p1, p4);
  if (d2 == 0 || d3 == 0 || d4 == 0) return false;
  if (d2 == d3 && 2 * d2 == d4 && 2 * distSq(p2, p4) == distSq(p2, p3)) {
    return true;
  }
  if (d3 == d4 && 2 * d3 == d2 && 2 * distSq(p3, p2) == distSq(p3, p4)) {
    return true;
  }
  if (d2 == d4 && 2 * d2 == d3 && 2 * distSq(p2, p3) == distSq(p2, p4)) {
    return true;
  }
  return false;
}
long long solve() {
  long long ans = 1e15;
  for (long long i = 1; i < 5; i++)
    for (long long j = 1; j < 4; j++) {
      point[i][j] = {
          -1 * (point[i][j - 1].second - root[i].second) + root[i].first,
          (point[i][j - 1].first - root[i].first) + root[i].second};
    }
  for (long long i = 0; i < 4; i++) {
    for (long long j = 0; j < 4; j++) {
      for (long long k = 0; k < 4; k++) {
        for (long long l = 0; l < 4; l++) {
          if (isSquare(point[1][i], point[2][j], point[3][k], point[4][l])) {
            ans = min(ans, i + j + k + l);
          }
        }
      }
    }
  }
  return (ans == 1e15 ? -1 : ans);
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  long long t;
  cin >> t;
  while (t--) {
    for (long long i = 1; i < 5; i++)
      cin >> point[i][0].first >> point[i][0].second >> root[i].first >>
          root[i].second;
    cout << solve() << "\n";
  }
}
