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;
const long double PI = (long double)3.1415926535897932;
const long double e = 1e-9;
template <typename T>
class point;
template <typename T>
class segment;
template <typename T>
class line;
template <typename T>
bool is_one_sign(const T &a, const T &b) {
  return ((a > -e && b > -e) || (a < e && b < e));
}
template <typename T>
bool is_eq(const T &a, const T &b) {
  return fabs((long double)(a - b)) < e;
}
template <typename T>
class point {
  friend class segment<T>;
  friend class line<T>;
  friend istream &operator>>(istream &os, point<T> &a) {
    os >> a.x >> a.y;
    return os;
  }
  friend ostream &operator<<(ostream &os, point<T> &a) {
    os << a.x << " " << a.y;
    return os;
  }
  T x, y;

 public:
  point(){};
  point(const T &x, const T &y) : x(x), y(y){};
  point operator+=(const point<T> &a) {
    x += a.x;
    y += a.y;
    return *this;
  }
  point operator-=(const point<T> &a) {
    x -= a.x;
    y -= a.y;
    return *this;
  }
  point operator*=(const T &a) {
    x *= a;
    y *= a;
    return *this;
  }
  T len() const { return (T)sqrt((long double)(x * x + y * y)); }
  T distance(const point<T> &a) const { return (a - (*this)).len(); }
  point<T> norm() const { return (*this) * (1 / len()); }
  point operator+(const point<T> &a) const { return point(a.x + x, a.y + y); }
  point operator-(const point<T> &a) const { return point(x - a.x, y - a.y); }
  T operator%(const point &a) const { return x * a.x + y * a.y; }
  T operator*(const point &a) const { return x * a.y - y * a.x; }
  T get_tan() const { return (T)(y / x); }
  T remake(const T &angle) const {
    if (angle >= 0) return angle;
    return angle + 2 * PI;
  }
  T get_angle() const {
    return remake(atan2(y / (*this).len(), x / (*this).len()));
  }
  point<T> get_perpendicular() const { return point<T>(-y, x); }
  point<T> rotate(T angle) const {
    return point<T>((T)(x * cos(angle) - sin(angle) * y),
                    (T)(x * sin(angle) + y * cos(angle)));
  }
};
template <typename T>
point<T> operator*(const point<T> &a, const T &b) {
  return point<T>(a.x * b, a.y * b);
}
template <typename T>
point<T> operator*(const T &b, const point<T> &a) {
  return point<T>(a.x * b, a.y * b);
}
template <typename T>
class segment {
  friend class point<T>;
  friend class line<T>;
  friend istream &operator>>(istream &os, segment<T> &a) {
    os >> a.first_point >> a.second_point;
    return os;
  }
  friend ostream &operator<<(ostream &os, segment<T> &a) {
    os << "SEGMENT: " << a.first_point << " " << a.second_point;
    return os;
  }
  point<T> first_point, second_point;

 public:
  segment(){};
  segment(const point<T> &first_point, const point<T> &second_point)
      : first_point(first_point), second_point(second_point) {}
  bool in_one_side(const point<T> &a, const point<T> &b) const {
    return is_one_sign((a - first_point) * (second_point - first_point),
                       (b - first_point) * (second_point - first_point));
  }
  T len() const { return ((second_point - first_point).len()); }
  bool lie(const point<T> &a) const {
    return (is_eq((a - first_point) * (second_point - first_point), (T)0.0) &&
            (((a - first_point) % (second_point - first_point)) >= 0) &&
            ((a - second_point) % (first_point - second_point)) >= 0);
  }
  T distance(const point<T> &a) const {
    if (((a - first_point) % (second_point - first_point)) < 0) {
      return a.distance(first_point);
    }
    if (((a - second_point) % (first_point - second_point)) < 0) {
      return a.distance(second_point);
    }
    return (fabs((a - first_point) * (second_point - first_point))) /
           (*this).len();
  }
  T operator[](const T &x) const {
    return first_point.y + (second_point.y - first_point.y) *
                               (x - first_point.x) /
                               (second_point.x - first_point.x);
  }
  bool is_intersect(const segment<T> &a) {
    if (a.lie(this->first_point) || a.lie(this->second_point) ||
        this->lie(a.first_point) || this->lie(a.second_point)) {
      return 1;
    }
    if (this->in_one_side(a.first_point, a.second_point) ||
        a.in_one_side(this->first_point, this->second_point)) {
      return 0;
    }
    return 1;
  }
  point<T> intersect(const segment<T> &a) const {
    if (a.lie(this->first_point)) {
      return this->first_point;
    }
    if (a.lie(this->second_point)) {
      return this->second_point;
    }
    if (this->lie(a.first_point)) {
      return a.first_point;
    }
    if (this->lie(a.second_point)) {
      return a.second_point;
    }
    return (line<T>(a)).intersect(line<T>(*this));
  }
};
template <typename T>
class line {
  friend class segment<T>;
  friend class point<T>;
  friend istream &operator>>(istream &os, line<T> &a) {
    os >> a.a >> a.b >> a.c;
    return os;
  }
  friend ostream &operator<<(ostream &os, line<T> &a) {
    os << "LINE: " << a.a << " " << a.b << " " << a.c;
    return os;
  }
  T a, b, c;

 public:
  line() : a(0), b(0), c(0){};
  line(const T &a, const T &b, const T &c) : a(a), b(b), c(c){};
  line(const point<T> &a, const point<T> &b)
      : a(a.y - b.y), b(b.x - a.x), c(a.x * b.y - b.x * a.y){};
  line(const segment<T> &a) { *this = line(a.first_point, a.second_point); }
  bool lie(const point<T> &cur) const {
    return is_eq(a * cur.x + b * cur.y + c, (T)0.0);
  }
  point<T> intersect(const line<T> &f) {
    assert(!is_eq((long double)f.a * b - f.b * a, (long double)0.0));
    return point<T>((-f.c * b + c * f.b) / (f.a * b - f.b * a),
                    (-f.a * c + a * f.c) / (f.a * b - f.b * a));
  }
  T distance(const point<T> &cur) const {
    return fabs(cur.x * a + cur.y * b + c) / (sqrt(a * a + b * b));
  }
};
bool is_square(point<long double> pos[4]) {
  vector<long double> di;
  for (int i = 0; i < 4; i++) {
    for (int j = i + 1; j < 4; j++) {
      di.push_back(pos[i].distance(pos[j]));
    }
  }
  assert(((int)(di.size())) == 6);
  sort(di.begin(), di.end());
  for (int i = 0; i < 3; i++) {
    if (!is_eq(di[i], di[i + 1])) {
      return 0;
    }
  }
  if (is_eq(di[0], (long double)0.0)) {
    return 0;
  }
  if (!is_eq(di[4], di[5])) {
    return 0;
  }
  if (!is_eq(di[3] * sqrt(2.0), di[4])) {
    return 0;
  }
  return 1;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.setf(ios::fixed);
  cout.precision(20);
  point<long double> home[4], pos[4];
  int n;
  cin >> n;
  for (int it = 0; it < n; it++) {
    for (int l = 0; l < 4; l++) {
      cin >> pos[l] >> home[l];
    }
    int j[4];
    int ans = 1000;
    for (j[0] = 0; j[0] < 4; j[0]++)
      for (j[1] = 0; j[1] < 4; j[1]++)
        for (j[2] = 0; j[2] < 4; j[2]++)
          for (j[3] = 0; j[3] < 4; j[3]++) {
            int cur_sum = 0;
            for (int l : j) cur_sum += l;
            point<long double> cur[4];
            for (int l = 0; l < 4; l++) {
              cur[l] = (pos[l] - home[l]).rotate(2 * PI / 4 * j[l]) + home[l];
            }
            if (is_square(cur)) {
              ans = min(ans, cur_sum);
            }
          }
    if (ans > 100) {
      cout << -1 << '\n';
    } else {
      cout << ans << '\n';
    }
  }
  return 0;
}
