#include <bits/stdc++.h>
using namespace std;
const int N = 5e3 + 99;
complex<int> read() {
  int x, y;
  cin >> x >> y;
  return complex<int>(x, y);
}
long double dist(complex<int> a, complex<int> b) {
  return hypot(abs(a.real() - b.real()), abs(a.imag() - b.imag()));
}
complex<long double> conv(complex<int> a) {
  return complex<long double>(a.real(), a.imag());
}
bool _90_deg(complex<int> a, complex<int> b, complex<int> c) {
  return fabs(((conj(((conv(b)) - (conv(a)))) * (((conv(c)) - (conv(b)))))
                   .real())) < 1e-9;
}
bool isSquare(vector<complex<int>> vec) {
  sort(vec.begin(), vec.end(), [](complex<int> a, complex<int> b) {
    if (a.real() == b.real()) return a.imag() < b.imag();
    return a.real() < b.real();
  });
  long double len = dist(vec[0], vec[1]);
  if (fabs(len) < 1e-9) return false;
  vector<pair<int, int>> _ = {{0, 2}, {1, 3}, {2, 3}};
  for (auto cur : _) {
    auto __ = dist(vec[cur.first], vec[cur.second]);
    if (fabs(len - dist(vec[cur.first], vec[cur.second])) > 1e-9) return false;
  }
  long double diag1 = dist(vec[1], vec[2]);
  long double diag2 = dist(vec[0], vec[3]);
  if (fabs(diag1 - diag2) > 1e-9) return false;
  swap(vec[2], vec[3]);
  for (int i = 0; i < 4; ++i) vec.push_back(vec[i]);
  for (int i = 2; i < vec.size(); ++i) {
    if (!_90_deg(vec[i - 2], vec[i - 1], vec[i])) {
      return false;
    }
  }
  return true;
}
vector<complex<int>> home;
int go(int i, vector<complex<int>> vec) {
  if (i >= 4) {
    return isSquare(vec) ? 0 : 1e9;
  }
  int ret = 1e9;
  for (int j = 0; j < 4; ++j) {
    ret = min(ret, go(i + 1, vec) + j);
    vec[i] -= home[i];
    complex<int> r(-vec[i].imag(), vec[i].real());
    vec[i] = r + home[i];
  }
  return ret;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  home.resize(4);
  int t;
  cin >> t;
  while (t--) {
    vector<complex<int>> v(4);
    for (int i = 0; i < 4; ++i) {
      v[i] = read();
      home[i] = read();
    }
    int ret = go(0, v);
    cout << (ret > 1e8 ? -1 : ret) << "\n";
  }
  return 0;
}
