# Captain Marmot

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 (x i, y i) 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 (a i, b i). Moving this mole one time means rotating his position point (x i, y i) 90 degrees counter-clockwise around it’s home point (a i, b i).

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 x iy ia ib i ( - 104 ≤ x i, y i, a i, b i ≤ 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

41 1 0 0-1 1 0 0-1 1 0 01 -1 0 01 1 0 0-2 1 0 0-1 1 0 01 -1 0 01 1 0 0-1 1 0 0-1 1 0 0-1 1 0 02 2 0 1-1 0 0 -23 0 0 -2-1 1 -2 0

output

1-133

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.

Solution:

#include <cstring>
#include <vector>
#include  <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <memory.h>
#include <cassert>

using namespace std;

struct Point {
long long x;
long long y;
};

long long dist(Point a, Point b) {
return (a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y);
}

bool test(Point a, Point b, Point c, Point d) {
Point m;
m.x = (a.x + b.x + c.x + d.x) / 4;
m.y = (a.y + b.y + c.y + d.y) / 4;
Point p[4];
p[0] = a;
p[1] = b;
p[2] = c;
p[3] = d;
if (dist(m, p[0]) == 0) {
return false;
}
for (int i = 0; i < 4; i++) {
if (dist(m, p[i]) != dist(m, p[0])) {
return false;
}
}
for (int i = 0; i < 4; i++) {
for (int j = i + 1; j < 4; j++) {
if (dist(p[i], p[j]) == 0) {
return false;
}
long long smul = (p[i].x - m.x) * (p[j].x - m.x) + (p[i].y - m.y) * (p[j].y - m.y);
long long vmul = (p[i].x - m.x) * (p[j].y - m.y) - (p[i].y - m.y) * (p[j].x - m.x);
if (smul != 0 && vmul != 0) {
return false;
}
}
}
return true;
}

Point p[42][42];

int main() {
int tt;
scanf("%d", &tt);
while (tt--) {
for (int i = 0; i < 4; i++) {
int xx, yy, aa, bb;
scanf("%d %d %d %d", &xx, &yy, &aa, &bb);
p[i][0].x = xx;
p[i][0].y = yy;
for (int j = 1; j < 4; j++) {
p[i][j].x = aa - (p[i][j - 1].y - bb);
p[i][j].y = bb + (p[i][j - 1].x - aa);
}
for (int j = 0; j < 4; j++) {
p[i][j].x *= 4;
p[i][j].y *= 4;
}
}
int ans = 12345;
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 4; j++) {
for (int k = 0; k < 4; k++) {
for (int w = 0; w < 4; w++) {
if (i + j + k + w < ans && test(p[0][i], p[1][j], p[2][k], p[3][w])) {
ans = i + j + k + w;
}
}
}
}
}
printf("%d\n", (ans == 12345 ? -1 : ans));
}
return 0;
}