#include <bits/stdc++.h>
using namespace std;
template <class T>
typename T::value_type arr_sum(const T &v, int n) {
  typename T::value_type sum = 0;
  for (int i = (0); i < (n); ++i) sum += v[i];
  return sum;
}
struct Sync_stdio {
  Sync_stdio() {
    cin.tie(NULL);
    ios_base::sync_with_stdio(false);
  }
} _sync_stdio;
void rot90(int &x, int &y) {
  int x1 = -y;
  int y1 = x;
  x = x1;
  y = y1;
}
void rotate90(vector<vector<int>> &v, int k, int count1) {
  int x = v[k][0] - v[k][2];
  int y = v[k][1] - v[k][3];
  for (int i = (0); i < (count1); ++i) {
    rot90(x, y);
  }
  v[k][0] = v[k][2] + x;
  v[k][1] = v[k][3] + y;
}
long long dist2(vector<int> &v1, vector<int> &v2) {
  return (long long)(v1[0] - v2[0]) * (v1[0] - v2[0]) +
         (long long)(v1[1] - v2[1]) * (v1[1] - v2[1]);
}
int square(vector<vector<int>> &v) {
  vector<long long> s;
  s.push_back(dist2(v[0], v[1]));
  s.push_back(dist2(v[0], v[2]));
  s.push_back(dist2(v[0], v[3]));
  s.push_back(dist2(v[1], v[2]));
  s.push_back(dist2(v[1], v[3]));
  s.push_back(dist2(v[2], v[3]));
  sort(s.begin(), s.end());
  if (s[0] != 0 && s[0] == s[1] && s[1] == s[2] && s[2] == s[3] &&
      2 * s[0] == s[4] && 2 * s[0] == s[5]) {
    return 1;
  }
  return 0;
}
int main() {
  int n;
  cin >> n;
  vector<vector<int>> v(4, vector<int>(4));
  for (int t = (0); t < (n); ++t) {
    int minr = 90000;
    for (int i = 0; i < 4; ++i)
      for (int j = 0; j < 4; ++j) cin >> v[i][j];
    ;
    for (int i = (0); i < (4); ++i) {
      for (int j = (0); j < (4); ++j) {
        for (int k = (0); k < (4); ++k) {
          for (int l = (0); l < (4); ++l) {
            vector<vector<int>> v2 = v;
            rotate90(v2, 0, i);
            rotate90(v2, 1, j);
            rotate90(v2, 2, k);
            rotate90(v2, 3, l);
            if (square(v2) && i + j + k + l < minr) {
              minr = i + j + k + l;
            }
          }
        }
      }
    }
    if (minr == 90000) {
      cout << -1 << "\n";
    } else {
      cout << minr << "\n";
    }
  }
}
