Captain Marmot wants to prepare a huge and important battle against his enemy, Captain Snake. For this battle he has n regiments, each consisting of 4 moles.

Initially, each mole i (1 ≤ i ≤ 4n) is placed at some position (xi, yi) in the Cartesian plane. Captain Marmot wants to move some moles to make the regiments compact, if it's possible.

Each mole i has a home placed at the position (ai, bi). Moving this mole one time means rotating his position point (xi, yi) 90 degrees counter-clockwise around it's home point (ai, bi).

A regiment is compact only if the position points of the 4 moles form a square with non-zero area.

Help Captain Marmot to find out for each regiment the minimal number of moves required to make that regiment compact, if it's possible.

Input

The first line contains one integer n (1 ≤ n ≤ 100), the number of regiments.

The next 4n lines contain 4 integers xi, yi, ai, bi ( - 104 ≤ xi, yi, ai, bi ≤ 104).

Output

Print n lines to the standard output. If the regiment i can be made compact, the i-th line should contain one integer, the minimal number of required moves. Otherwise, on the i-th line print "-1" (without quotes).

Examples

Input

4
1 1 0 0
-1 1 0 0
-1 1 0 0
1 -1 0 0
1 1 0 0
-2 1 0 0
-1 1 0 0
1 -1 0 0
1 1 0 0
-1 1 0 0
-1 1 0 0
-1 1 0 0
2 2 0 1
-1 0 0 -2
3 0 0 -2
-1 1 -2 0


Output

1
-1
3
3

Note

In the first regiment we can move once the second or the third mole.

We can't make the second regiment compact.

In the third regiment, from the last 3 moles we can move once one and twice another one.

In the fourth regiment, we can move twice the first mole and once the third mole.
#include <bits/stdc++.h>
using namespace std;
void file() {}
void fast() {
  std::ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
}
long long gcd(long long a, long long b) { return !b ? a : gcd(b, a % b); }
long long lcm(long long a, long long b) { return (a / gcd(a, b)) * b; }
long long setbit(long long num, int idx, int val = 1) {
  return (val) ? (num | (1 << idx)) : (num & ~(1 << idx));
}
long long getbit(long long num, int idx) { return ((num >> idx) & 1) == 1; }
int contbit(int num) {
  int ret = 0;
  while (num) {
    if (num % 2) ret++;
    num /= 2;
  }
  return ret;
}
int dx[] = {-1, 0, 0, 1, 1, 1, -1, -1};
int dy[] = {0, 1, -1, 0, 1, -1, 1, -1};
int dcmp(double x, double y) {
  return fabs(x - y) <= 1e-4 ? 0 : x < y ? -1 : 1;
}
namespace std {
bool operator<(const complex<long double>& a, const complex<long double>& b) {
  return dcmp(a.real(), b.real()) == -1  ? 1
         : dcmp(a.real(), b.real()) == 1 ? 0
         : dcmp(a.imag(), b.imag()) != 1 ? 1
                                         : 0;
}
bool operator>(const complex<long double>& a, const complex<long double>& b) {
  return dcmp(a.real(), b.real()) == 1    ? 1
         : dcmp(a.real(), b.real()) == -1 ? 0
         : dcmp(a.imag(), b.imag()) != -1 ? 1
                                          : 0;
}
}  // namespace std
bool comPoints(complex<long double> a, complex<long double> b) {
  if (dcmp(a.real(), b.real())) return dcmp(a.real(), b.real()) == -1;
  return dcmp(a.imag(), b.imag()) == -1;
}
complex<long double> readPoint() {
  long double x, y;
  cin >> x >> y;
  return complex<long double>(x, y);
}
void printPoint(complex<long double> P) {
  cout << (int)P.real() << " " << (int)P.imag();
}
double fixDoubleMod(double a, double k) { return fmod(fmod(a, k) + k, k); }
double toDeg(double d) {
  d = fixDoubleMod(d, 2 * acos(-1.0));
  return (d * 180 / acos(-1.0));
}
double toRad(double d) { return (d * acos(-1.0)) / 180.0; }
bool paralelLines(complex<long double> a, complex<long double> b,
                  complex<long double> c, complex<long double> d) {
  return fabs(((conj(((a) - (b))) * (((d) - (c)))).imag())) < 1e-4;
}
bool prependecularVec(const complex<long double>& a,
                      const complex<long double>& b) {
  return dcmp(((conj(a) * (b)).real()), 0) == 0;
}
bool isSquare_ABCD(vector<complex<long double>> v) {
  return paralelLines(v[0], v[1], v[2], v[3]) &&
         prependecularVec(((v[1]) - (v[0])), ((v[3]) - (v[0]))) &&
         prependecularVec(((v[1]) - (v[0])), ((v[1]) - (v[2]))) &&
         dcmp(fabs(((conj(((v[1]) - (v[0]))) * (((v[3]) - (v[0])))).imag())),
              0) == 1 &&
         dcmp(((long double)hypot((((v[1]) - (v[0]))).imag(),
                                  (((v[1]) - (v[0]))).real())),
              ((long double)hypot((((v[2]) - (v[1]))).imag(),
                                  (((v[2]) - (v[1]))).real()))) == 0;
}
bool canMakeSquare(vector<complex<long double>> v) {
  sort((v).begin(), (v).end(), comPoints);
  do {
    if (isSquare_ABCD(v)) return 1;
  } while (next_permutation((v).begin(), (v).end(), comPoints));
  return 0;
}
int main() {
  file();
  fast();
  int t;
  cin >> t;
  while (t--) {
    vector<pair<pair<long double, double>, complex<long double>>> a(4);
    for (int i = 0; i < 4; i++) {
      complex<long double> p = readPoint();
      a[i].second = readPoint();
      p = ((p) - (a[i].second));
      a[i].first.first = ((long double)hypot((p).imag(), (p).real()));
      a[i].first.second = (atan2((p).imag(), (p).real()));
    }
    int mn = 1e9;
    for (int i1 = 0; i1 <= 270; i1 += 90)
      for (int i2 = 0; i2 <= 270; i2 += 90)
        for (int i3 = 0; i3 <= 270; i3 += 90)
          for (int i4 = 0; i4 <= 270; i4 += 90) {
            double ang1 =
                toRad(fixDoubleMod(toDeg(a[0].first.second) + i1, 360.0));
            double ang2 =
                toRad(fixDoubleMod(toDeg(a[1].first.second) + i2, 360.0));
            double ang3 =
                toRad(fixDoubleMod(toDeg(a[2].first.second) + i3, 360.0));
            double ang4 =
                toRad(fixDoubleMod(toDeg(a[3].first.second) + i4, 360.0));
            vector<complex<long double>> v(4);
            v[0] = a[0].second +
                   ((a[0].first.first) * exp(complex<long double>(0, (ang1))));
            v[1] = a[1].second +
                   ((a[1].first.first) * exp(complex<long double>(0, (ang2))));
            v[2] = a[2].second +
                   ((a[2].first.first) * exp(complex<long double>(0, (ang3))));
            v[3] = a[3].second +
                   ((a[3].first.first) * exp(complex<long double>(0, (ang4))));
            if (canMakeSquare(v)) mn = min(mn, (i1 + i2 + i3 + i4) / 90);
          }
    if (mn == 1e9) mn = -1;
    cout << mn << "\n";
  }
}
