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.


import java.util.Scanner;

public class CaptainMarmot2 
{
	static int[][] x, y;
	static int[] hx, hy;
	static Point pp1 = new Point();
	static Point pp2 = new Point();
	static Point pp3 = new Point();
	static Point pp4 = new Point();
	static double TOLERANCE = 0.001d;
	static boolean debug = false;
	
	static boolean approxeq(double d1, double d2)
	{
		return (Math.abs(d1 - d2) <= TOLERANCE);
	}
	
	static double dist(Point p1, Point p2)
	{
		return Math.sqrt(Math.pow(p1.x - p2.x, 2) + Math.pow(p1.y - p2.y, 2));
	}
	
	static boolean check(Point p1, Point p2, Point p3, Point p4)
	{

		
		double d12 = dist(p1, p2);
		double d34 = dist(p3, p4);
		double d14 = dist(p1, p4);
		double d23 = dist(p2, p3);
		double d24 = dist(p2, p4);
		double d13 = dist(p1, p3);
		
		if(d12 == d23 && d12 == d34 && d12 == d14)
//		if(approxeq(d12, d23) && approxeq(d12, d34) && approxeq(d12, d14))
		{
			if(approxeq(Math.pow(d13, 2), Math.pow(d12,2) + Math.pow(d23,2)))
			{
				return true;
			}
			else
			{
//				System.out.println(Math.abs(Math.pow(d14, 2) - (Math.pow(d12,2) + Math.pow(d24,2))));
			}
				
		}
		
		return false;
	}
	
	static class Point implements Comparable<Point>
	{
		int x, y;
		public Point(int x0, int y0)
		{
			x = x0;
			y = y0;
		}
		public Point()
		{
		}
		@Override
		public int compareTo(Point arg0) 
		{
			return ((x - arg0.x)*100000) + y - arg0.y;
		}
	}
	
	static void rotate()
	{
		for(int id = 0; id < 4; id++)
		{
			
			for(int rot = 1; rot < 4; rot++)
			{
				int relx = x[id][rot-1] - hx[id];
				int rely = y[id][rot-1] - hy[id];
				int newx = -rely + hx[id];
				int newy = relx + hy[id];
				x[id][rot] = newx;
				y[id][rot] = newy;
			}
		}
	}
	
	public static void main(String[] args) 
	{
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		
		for(int i = 0; i < n; i++)
		{
			x = new int[4][4];
			y = new int[4][4];
			hx = new int[4];
			hy = new int[4];
			
			for(int mole = 0; mole < 4; mole++)
			{
				x[mole][0] = sc.nextInt();
				y[mole][0] = sc.nextInt();
				hx[mole] = sc.nextInt();
				hy[mole] = sc.nextInt();
			}
			rotate();
			
			int min = 999; //max is actually 12
			int cur = 0;
			
			for(int a = 0; a < 4; a++)
			{
				pp1.x = x[0][a];
				pp1.y = y[0][a];
				for(int b = 0; b < 4; b++)
				{
					pp2.x = x[1][b];
					pp2.y = y[1][b];
					if(pp2.x == pp1.x && pp2.y == pp1.y)continue;
					for(int c = 0; c < 4; c++)
					{
						pp3.x = x[2][c];
						pp3.y = y[2][c];
						if(pp3.x == pp1.x && pp3.y == pp1.y)continue;
						if(pp3.x == pp2.x && pp3.y == pp2.y)continue;
						for(int d = 0; d < 4; d++)
						{
							cur = a + b + c + d;
							//check if square
//							System.out.println(cur + " " + a + " " + b + " " + c + " " + d);
							

							pp4.x = x[3][d];
							pp4.y = y[3][d];
							if(pp4.x == pp1.x && pp4.y == pp1.y)continue;
							if(pp4.x == pp2.x && pp4.y == pp2.y)continue;
							if(pp4.x == pp3.x && pp4.y == pp3.y)continue;
							
							if(cur == 0)debug = true;
							if(check(pp1,pp2,pp3,pp4) || check(pp1,pp3,pp2,pp4) || check(pp1,pp4,pp3,pp2)||check(pp1,pp2,pp4,pp3) || check(pp1,pp3,pp4,pp2) || check(pp1,pp4,pp2,pp3))
							{
//								System.out.println("Square: " + x[0][a] + " " + y[0][a] + ", " + x[1][b] + " " + y[1][b] + ", " + x[2][c] + " " + y[2][c] + ", " + x[3][d] + " " + y[3][d]);
								min = Math.min(min, cur);
							}
							debug = false;
						}
					}
				}
			}
			
			if(min == 999)min = -1;
			System.out.println(min);
			
		}

	}

}
