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 Main
{
	public static class Point
	{
		double x;
		double y;
		public Point(double x, double y)
		{
			this.x = x;
			this.y = y;
		}
		@Override
		public int hashCode()
		{
			final int prime = 31;
			int result = 1;
			long temp;
			temp = Double.doubleToLongBits(x);
			result = prime * result + (int) (temp ^ (temp >>> 32));
			temp = Double.doubleToLongBits(y);
			result = prime * result + (int) (temp ^ (temp >>> 32));
			return result;
		}
		@Override
		public boolean equals(Object obj)
		{
			if (this == obj)
				return true;
			if (obj == null)
				return false;
			if (getClass() != obj.getClass())
				return false;
			Point other = (Point) obj;
			if (Double.doubleToLongBits(x) != Double.doubleToLongBits(other.x))
				return false;
			if (Double.doubleToLongBits(y) != Double.doubleToLongBits(other.y))
				return false;
			return true;
		}
	}
	public static class Mole
	{
		int x;
		int y;
		int h_x;
		int h_y;
		int moves;
		public Mole()
		{
		}
		public Mole(int x, int y, int h_x, int h_y)
		{
			this.x = x;
			this.y = y;
			this.h_x = h_x;
			this.h_y = h_y;
		}
	}
	public static void main(String[] args)
	{
		Scanner sc = new Scanner(System.in);
		int amount = sc.nextInt();
		for(int i = 0; i < amount; i++)
		{
			Mole mole[] = new Mole[4];
			mole[0] = new Mole(sc.nextInt(), sc.nextInt(),sc.nextInt(),sc.nextInt());
			mole[1] = new Mole(sc.nextInt(), sc.nextInt(),sc.nextInt(),sc.nextInt());
			mole[2] = new Mole(sc.nextInt(), sc.nextInt(),sc.nextInt(),sc.nextInt());
			mole[3] = new Mole(sc.nextInt(), sc.nextInt(),sc.nextInt(),sc.nextInt());
			int finalmoves = -1;
			Point[] moles = new Point[4];
			for(int j = 0; j < 4; j++)
			{
				mole[0].moves = j;
				moles[0] = new Point(Math.round(mole[0].h_x - Math.sin(mole[0].moves * Math.PI / 2) * (mole[0].y - mole[0].h_y) + Math.cos(mole[0].moves * Math.PI / 2) * (mole[0].x - mole[0].h_x)),
						Math.round(mole[0].h_y + Math.sin(mole[0].moves * Math.PI / 2) * (mole[0].x - mole[0].h_x) + Math.cos(mole[0].moves * Math.PI / 2) * (mole[0].y - mole[0].h_y)));
				for(int k = 0; k < 4; k++)
				{
					mole[1].moves = k;
					moles[1] = new Point(Math.round(mole[1].h_x - Math.sin(mole[1].moves * Math.PI / 2) * (mole[1].y - mole[1].h_y) + Math.cos(mole[1].moves * Math.PI / 2) * (mole[1].x - mole[1].h_x)),
							Math.round(mole[1].h_y + Math.sin(mole[1].moves * Math.PI / 2) * (mole[1].x - mole[1].h_x) + Math.cos(mole[1].moves * Math.PI / 2) * (mole[1].y - mole[1].h_y)));
					for(int l = 0; l < 4; l++)
					{
						mole[2].moves = l;
						moles[2] = new Point(Math.round(mole[2].h_x - Math.sin(mole[2].moves * Math.PI / 2) * (mole[2].y - mole[2].h_y) + Math.cos(mole[2].moves * Math.PI / 2) * (mole[2].x - mole[2].h_x)),
								Math.round(mole[2].h_y + Math.sin(mole[2].moves * Math.PI / 2) * (mole[2].x - mole[2].h_x) + Math.cos(mole[2].moves * Math.PI / 2) * (mole[2].y - mole[2].h_y)));
						for(int m = 0; m < 4; m++)
						{
							mole[3].moves = m;
							int currentmoves = mole[0].moves + mole[1].moves + mole[2].moves + mole[3].moves;
							moles[3] = new Point(Math.round(mole[3].h_x - Math.sin(mole[3].moves * Math.PI / 2) * (mole[3].y - mole[3].h_y) + Math.cos(mole[3].moves * Math.PI / 2) * (mole[3].x - mole[3].h_x)),
									Math.round(mole[3].h_y + Math.sin(mole[3].moves * Math.PI / 2) * (mole[3].x - mole[3].h_x) + Math.cos(mole[3].moves * Math.PI / 2) * (mole[3].y - mole[3].h_y)));
							if(isSquare(moles))
							{
								if(currentmoves < finalmoves || finalmoves == -1)
									finalmoves = currentmoves;
								if(currentmoves == 1) j = 4;
							}
						}
					}
				}
			}
			System.out.println(finalmoves);
		}
		sc.close();
	}
	public static boolean isSquare(Point[] moles)
	{
		if(moles[0].equals(moles[1]))
			return false;
		else if(moles[0].equals(moles[2]))
			return false;
		else if(moles[0].equals(moles[3]))
			return false;
		else if(moles[1].equals(moles[2]))
			return false;
		else if(moles[1].equals(moles[3]))
			return false;
		else if(moles[2].equals(moles[3]))
			return false;
		if(equalSides(moles[0], moles[1], moles[2], moles[3]))
		{
			if(equalAngles(moles[0], moles[1], moles[2], moles[3]))
				return true;
		}
		else if(equalSides(moles[0], moles[1], moles[3], moles[2]))
		{
			if(equalAngles(moles[0], moles[1], moles[3], moles[2]))
				return true;
		}
		else if(equalSides(moles[0], moles[2], moles[1], moles[3]))
		{
			if(equalAngles(moles[0], moles[2], moles[1], moles[3]))
				return true;
		}
		return false;
	}
	public static boolean equalSides(Point mole1, Point mole2, Point mole3, Point mole4)
	{
		double side1 = Math.sqrt(Math.pow(mole1.x - mole2.x, 2) + Math.pow(mole1.y - mole2.y, 2));
		double side2 = Math.sqrt(Math.pow(mole2.x - mole3.x, 2) + Math.pow(mole2.y - mole3.y, 2));
		double side3 = Math.sqrt(Math.pow(mole3.x - mole4.x, 2) + Math.pow(mole3.y - mole4.y, 2));
		double side4 = Math.sqrt(Math.pow(mole4.x - mole1.x, 2) + Math.pow(mole4.y - mole1.y, 2));
		if(side1 == side2)
			if(side2 == side3)
				if(side3 == side4)
					return true;
		return false;
	}
	public static boolean equalAngles(Point mole1, Point mole2, Point mole3, Point mole4)
	{
		double diagonal1 = Math.sqrt(Math.pow(mole1.x - mole3.x, 2) + Math.pow(mole1.y - mole3.y, 2));
		double diagonal2 = Math.sqrt(Math.pow(mole2.x - mole4.x, 2) + Math.pow(mole2.y - mole4.y, 2));
		if(diagonal1 == diagonal2)
			return true;
		return false;
	}
}
