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.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.InputMismatchException;
import java.util.LinkedList;
import java.util.Queue;
import java.util.TreeMap;
import java.util.TreeSet;


public class Captain474C {
	
	class Point {
		int x,y,a,b;
		Point(int x , int y , int a , int b) {
			this.x = x;
			this.y = y;
			this.a = a;
			this.b = b;
		}

		void rotate(Point p) {
			int t = p.x;
			int r = p.y;

			p.x = p.a + p.b - r;
			p.y = t + p.b - p.a;
		}

		double distance(Point p) {
			return Math.sqrt((p.x - this.x)*1l*(p.x - this.x) + (p.y - this.y)*1l*(p.y - this.y));
		}

		void display(Point p) {
			System.out.println(p.x+" "+p.y+" "+p.a+" "+p.b);
		}
		
		double slope(Point p) {
			return (p.y - this.y*1.0)/(p.x-this.x);
		}
	}

	
	class Marmot {
		Point a , b , c , d;
		Marmot(Point a , Point b , Point c , Point d) {
			this.a = a;
			this.b = b;
			this.c = c;
			this.d = d;
		}
	}
	
	
	InputStream is;
	PrintWriter out;
	String INPUT = "";


	int mod = (int)(Math.pow(10,9)+7);

	long gcd(long a, long b) 
	{ 
		if (b == 0) 
			return a; 
		return gcd(b, a % b);  
	} 
	int d = 0;

	Point np() {
		int x = ni();
		int y = ni();
		int a = ni();
		int b = ni();
		Point p = new Point(x,y,a,b);
		return p;
	}
	void solve()
	{	
		int n = ni();
		Marmot a[] = new Marmot[n];
		for(int i = 0 ; i<n ; i++) {
			Point p1 = np();
			Point p2 = np();
			Point p3 = np();
			Point p4 = np();
			a[i] = new Marmot(p1,p2,p3,p4);			
		}

		for(int i = 0 ; i<n ; i++) {
			min = Integer.MAX_VALUE;
			gen(a[i] , 0 , 0);
			out.println(min == Integer.MAX_VALUE ? -1 : min);
		}

	}
	int min = Integer.MAX_VALUE;

	int dp[][] = {
			{1,2,3,4},
			{2,1,3,4},
			{3,1,2,4},
			{1,3,2,4},
			{2,3,1,4},
			{3,2,1,4},
			{4,2,3,1},
			{2,4,3,1},
			{3,4,2,1},
			{4,3,2,1},
			{2,3,4,1},
			{3,2,4,1},
			{4,1,3,2},
			{1,4,3,2},
			{3,4,1,2},
			{4,3,1,2},
			{1,3,4,2},
			{3,1,4,2},
			{4,1,2,3},
			{1,4,2,3},
			{2,4,1,3},
			{4,2,1,3},
			{1,2,4,3},
			{2,1,4,3}				
	};

	void gen(Marmot m , int ct , int i) {

		if(i>3) { 
			if(check(m)) {
				/*out.println(m.a.x+" "+m.a.y+" "+ct);
				out.println(m.b.x+" "+m.b.y+" "+ct);
				out.println(m.c.x+" "+m.c.y+" "+ct);
				out.println(m.d.x+" "+m.d.y+" "+ct);*/

				min = Math.min(min, ct);
			}
			return;
		}

		if(i == 0) {
			gen(m , ct , i+1);
			m.a.rotate(m.a);
			gen(m , ct+1 , i+1);
			m.a.rotate(m.a);
			gen(m , ct+2 , i+1);
			m.a.rotate(m.a);
			gen(m , ct+3 , i+1);
			m.a.rotate(m.a);
		}


		if(i == 1) {
			gen(m , ct , i+1);
			m.b.rotate(m.b);
			gen(m , ct+1 , i+1);
			m.b.rotate(m.b);
			gen(m , ct+2 , i+1);
			m.b.rotate(m.b);
			gen(m , ct+3 , i+1);
			m.b.rotate(m.b);
		}


		if(i == 2) {
			gen(m , ct , i+1);
			m.c.rotate(m.c);
			gen(m , ct+1 , i+1);
			m.c.rotate(m.c);
			gen(m , ct+2 , i+1);
			m.c.rotate(m.c);
			gen(m , ct+3 , i+1);
			m.c.rotate(m.c);
		}

		if(i == 3) {
			gen(m , ct , i+1);
			m.d.rotate(m.d);
			gen(m , ct+1 , i+1);
			m.d.rotate(m.d);
			gen(m , ct+2 , i+1);
			m.d.rotate(m.d);
			gen(m , ct+3 , i+1);
			m.d.rotate(m.d);
		}


	}

	// 0 1 
	// 3 2
	boolean check(Marmot m) {
		Point abc[] = new Point[4];
		abc[0] = m.a;
		abc[1] = m.b;
		abc[2] = m.c;
		abc[3] = m.d;
		for(int i = 0 ; i<4 ; i++) {
			for(int j = 0 ; j<4 ; j++) {
				
				if(j!=i && abc[i].distance(abc[j]) == 0) return false;
			}
		}
		for(int i = 0 ; i<dp.length ; i++) {
			if(abc[dp[i][0]-1].distance(abc[dp[i][1]-1]) == abc[dp[i][1]-1].distance(abc[dp[i][2]-1]) 
					&& abc[dp[i][2]-1].distance(abc[dp[i][3]-1]) == abc[dp[i][3]-1].distance(abc[dp[i][0]-1])
					&& abc[dp[i][1]-1].distance(abc[dp[i][2]-1]) == abc[dp[i][2]-1].distance(abc[dp[i][3]-1])
					&& abc[dp[i][2]-1].distance(abc[dp[i][3]-1]) != 0		
					) {
				 /*out.println("dp "+i);
				 abc[0].display(abc[0]);
				 abc[1].display(abc[1]);
				 abc[2].display(abc[2]);
				 abc[3].display(abc[3]);*/
				double xy = abc[dp[i][0]-1].distance(abc[dp[i][1]-1]);
				xy = xy*xy;
				
				double rt = abc[dp[i][1]-1].distance(abc[dp[i][2]-1]);
				rt = rt*rt;
				
				double dest = abc[dp[i][0]-1].distance(abc[dp[i][2]-1]);
				dest = dest*dest;
				
				//out.println(xy+" "+rt+" "+dest);
				
				if(dest > xy && dest > rt && Math.abs(dest - xy - rt) <= 0.001)
					return true;
				
				//return true;
			}

		}

		return false;
	}

	void run() throws Exception
	{
		is = INPUT.isEmpty() ? System.in : new ByteArrayInputStream(INPUT.getBytes());
		out = new PrintWriter(System.out);

		long s = System.currentTimeMillis();
		solve();
		out.flush();
		if(!INPUT.isEmpty())tr(System.currentTimeMillis()-s+"ms");
	}

	public static void main(String[] args) throws Exception { new Captain474C().run(); }

	private byte[] inbuf = new byte[1024];
	public int lenbuf = 0, ptrbuf = 0;

	private int readByte()
	{
		if(lenbuf == -1)throw new InputMismatchException();
		if(ptrbuf >= lenbuf){
			ptrbuf = 0;
			try { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); }
			if(lenbuf <= 0)return -1;
		}
		return inbuf[ptrbuf++];
	}

	private boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); }
	private int skip() { int b; while((b = readByte()) != -1 && isSpaceChar(b)); return b; }

	private double nd() { return Double.parseDouble(ns()); }
	private char nc() { return (char)skip(); }

	private String ns()
	{
		int b = skip();
		StringBuilder sb = new StringBuilder();
		while(!(isSpaceChar(b))){ // when nextLine, (isSpaceChar(b) && b != ' ')
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	private char[] ns(int n)
	{
		char[] buf = new char[n];
		int b = skip(), p = 0;
		while(p < n && !(isSpaceChar(b))){
			buf[p++] = (char)b;
			b = readByte();
		}
		return n == p ? buf : Arrays.copyOf(buf, p);
	}

	private char[][] nm(int n, int m)
	{
		char[][] map = new char[n][];
		for(int i = 0;i < n;i++)map[i] = ns(m);
		return map;
	}

	private int[] na(int n)
	{
		int[] a = new int[n];
		for(int i = 0;i < n;i++)a[i] = ni();
		return a;
	}

	private int[][] na(int n , int m)
	{
		int[][] a = new int[n][m];
		for(int i = 0;i < n;i++) 
			for(int j = 0 ; j<m ; j++) a[i][j] = ni();
		return a;
	}

	private int ni()
	{
		int num = 0, b;
		boolean minus = false;
		while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
		if(b == '-'){
			minus = true;
			b = readByte();
		}

		while(true){
			if(b >= '0' && b <= '9'){
				num = num * 10 + (b - '0');
			}else{
				return minus ? -num : num;
			}
			b = readByte();
		}
	}

	private long nl()
	{
		long num = 0;
		int b;
		boolean minus = false;
		while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
		if(b == '-'){
			minus = true;
			b = readByte();
		}

		while(true){
			if(b >= '0' && b <= '9'){
				num = num * 10 + (b - '0');
			}else{
				return minus ? -num : num;
			}
			b = readByte();
		}
	}

	void display2D(int a[][]) {
		for(int i[] : a) {
			for(int j : i) {
				out.print(j+" ");
			}
			out.println();
		}
	}

	int[][] creategraph(int n , int m) {
		int g[][] = new int[n+1][];

		int from[] = new int[m];
		int to[] = new int[m];
		int ct[] = new int[n+1];

		for(int i = 0 ; i<m; i++) {
			from[i] = ni();
			to[i] = ni();
			ct[from[i]]++;
			ct[to[i]]++;
		}

		int parent[] = new int[n+1];

		for(int i = 0 ; i<n+1 ; i++) g[i] = new int[ct[i]];

		for(int i = 0 ; i<m ; i++) {
			g[from[i]][--ct[from[i]]] = to[i];
			g[to[i]][--ct[to[i]]] = from[i];
		}

		return g;
	}

	static long __gcd(long a, long b)
	{

		if(b == 0) 
		{
			return a;
		}
		else
		{
			return __gcd(b, a % b);
		}
	}

	// To compute x^y under modulo m
	static long power(long x, long y, long p)
	{

		// Initialize result
		long res = 1;

		// Update x if it is more than or
		// equal to p
		x = x % p;

		while (y > 0)
		{

			// If y is odd, multiply x
			// with result
			if (y % 2 == 1)
				res = (res * x) % p;

			// y must be even now
			y = y >> 1; // y = y/2
		x = (x * x) % p;
		}

		return res;
	}

	// Function to find modular 
	// inverse of a under modulo m
	// Assumption: m is prime
	static long modInverse(long a, int m)
	{
		if (__gcd(a, m) != 1) {
			//System.out.print("Inverse doesn't exist");
			return -1;
		}

		else {

			// If a and m are relatively prime, then
			// modulo inverse is a^(m-2) mode m
			//			System.out.println("Modular multiplicative inverse is "
			//											+power(a, m - 2, m));
			return power(a, m - 2, m);
		}
	}

	static long nCrModPFermat(int n, int r,
			int p , long fac[])
	{

		// Base case
		if (r == 0)
			return 1;

		// Fill factorial array so that we
		// can find all factorial of r, n
		// and n-r
		long t = (fac[n]* modInverse(fac[r], p))%p;

		return ( (t* modInverse(fac[n-r], p))% p);
	}


	private static void tr(Object... o) { System.out.println(Arrays.deepToString(o)); }
}