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.DataInputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.InputMismatchException;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.Random;
import java.util.Scanner;
import java.util.Stack;
import java.util.StringTokenizer;
import java.util.TreeMap;
import java.util.TreeSet;

public class SuffixArray {
	private static InputStream stream;
	private static byte[] buf = new byte[1024];
	private static int curChar;
	private static int numChars;
	private static SpaceCharFilter filter;
	private static PrintWriter pw;
	private static long max = Long.MIN_VALUE;
	private static int mod = 1000000000 + 7;
	private static boolean flag=false;
	private static int block;
	private static void soln() {
		int n=nextInt();
		for(int i=0;i<n;i++){
			int[][][] arr=new int[4][4][2];
			for(int j=0;j<4;j++){
				int x=nextInt();
				int y=nextInt();
				int a=nextInt();
				int b=nextInt();
				arr[j][0][0]=x;
				arr[j][0][1]=y;
				int x1=x-a;
				int y1=y-b;
				//System.out.println(x+" "+y);
				for(int k=0;k<3;k++){
					int tmp=y1;
					y1=x1;
					x1=tmp;
					x1=(-1)*x1;
					arr[j][k+1][0]=x1+a;
					arr[j][k+1][1]=y1+b;
					//System.out.println((x1+a)+" "+(y1+b));
				}
				//System.out.println();
			}
			int min=Integer.MAX_VALUE;
			int[][] arr2=new int[4][2];
			for(int a1=0;a1<4;a1++){
				arr2[0][0]=arr[0][a1][0];
				arr2[0][1]=arr[0][a1][1];
				for(int a2=0;a2<4;a2++){
					arr2[1][0]=arr[1][a2][0];
					arr2[1][1]=arr[1][a2][1];
					for(int a3=0;a3<4;a3++){
						arr2[2][0]=arr[2][a3][0];
						arr2[2][1]=arr[2][a3][1];
						for(int a4=0;a4<4;a4++){
							arr2[3][0]=arr[3][a4][0];
							arr2[3][1]=arr[3][a4][1];
							if(check(arr2))
								min=Math.min(min,a1+a2+a3+a4);
						}
					}
				}
			}
			if(min==Integer.MAX_VALUE)
				min=-1;
			pw.println(min);
		}
	}
	private static boolean check(int[][] arr){
		int a1=Math.abs(arr[0][0]-arr[1][0])*Math.abs(arr[0][0]-arr[1][0])+Math.abs(arr[0][1]-arr[1][1])*Math.abs(arr[0][1]-arr[1][1]);
		int a2=Math.abs(arr[1][0]-arr[2][0])*Math.abs(arr[1][0]-arr[2][0])+Math.abs(arr[1][1]-arr[2][1])*Math.abs(arr[1][1]-arr[2][1]);
		int a3=Math.abs(arr[2][0]-arr[3][0])*Math.abs(arr[2][0]-arr[3][0])+Math.abs(arr[2][1]-arr[3][1])*Math.abs(arr[2][1]-arr[3][1]);
		int a4=Math.abs(arr[0][0]-arr[3][0])*Math.abs(arr[0][0]-arr[3][0])+Math.abs(arr[0][1]-arr[3][1])*Math.abs(arr[0][1]-arr[3][1]);
		int a5=Math.abs(arr[0][0]-arr[2][0])*Math.abs(arr[0][0]-arr[2][0])+Math.abs(arr[0][1]-arr[2][1])*Math.abs(arr[0][1]-arr[2][1]);
		int a6=Math.abs(arr[1][0]-arr[3][0])*Math.abs(arr[1][0]-arr[3][0])+Math.abs(arr[1][1]-arr[3][1])*Math.abs(arr[1][1]-arr[3][1]);
		HashMap<Integer,Integer> m=new HashMap<>();
		m.put(a1,1);
		if(m.containsKey(a2))
			m.put(a2,m.get(a2)+1);
		else
			m.put(a2,1);
		if(m.containsKey(a3))
			m.put(a3,m.get(a3)+1);
		else
			m.put(a3,1);
		if(m.containsKey(a4))
			m.put(a4,m.get(a4)+1);
		else
			m.put(a4,1);
		if(m.containsKey(a5))
			m.put(a5,m.get(a5)+1);
		else
			m.put(a5,1);
		if(m.containsKey(a6))
			m.put(a6,m.get(a6)+1);
		else
			m.put(a6,1);
		if(m.size()==2){
			int[] cnt=new int[2];
			int i=0;
			for(int x:m.keySet()){
				if(x!=0){
					cnt[i]=m.get(x);
					i++;
				}
			}
			if((cnt[0]==2 && cnt[1]==4 )||(cnt[0]==4 && cnt[1]==2))
				return true;
		}
		return false;
	}
	/*static class Suffix implements Comparable<Suffix>{
		int index;
		int[] rank=new int[2];
		@Override
		public int compareTo(Suffix arg0){
			return (this.rank[0]==arg0.rank[0])?(this.rank[1]<arg0.rank[1]?-1:1):(this.rank[0]<arg0.rank[0]?-1:1);
		}	
	}
	private static int[] buildSuffix(String s,int n){
		Suffix[] arr=new Suffix[n];
		for(int i=0;i<n;i++)
			arr[i]=new Suffix();
		for(int i=0;i<n;i++){
			arr[i].index=i;
			arr[i].rank[0]=s.charAt(i)-'a';
			arr[i].rank[1]=((i+1)<n)?(s.charAt(i+1)-'a'):-1;
		}
		Arrays.sort(arr);
		//for(int i=0;i<n;i++)
			//System.out.print(arr[i].index);
		int[] ind=new int[n];
		for(int k=4;k<2*n;k=k*2){
			int rank=0;
			int p_rank=arr[0].rank[0];
			arr[0].rank[0]=rank;
			ind[arr[0].index]=0;
			for(int i=1;i<n;i++){
				if (arr[i].rank[0] == p_rank && arr[i].rank[1] == arr[i-1].rank[1]) {
	                p_rank = arr[i].rank[0];
	                arr[i].rank[0] = rank;
	            }
	            else{
	                p_rank = arr[i].rank[0];
	                arr[i].rank[0] = ++rank;
	            }
	            ind[arr[i].index] = i;
	        }
			for(int i=0;i<n;i++){
				int n_index=arr[i].index + k/2;
				arr[i].rank[1]=(n_index<n)?arr[ind[n_index]].rank[0] : -1;
			}
			Arrays.sort(arr);
		}
		int[] suffixArr=new int[n];
		for(int i=0;i<n;i++)
			suffixArr[i]=arr[i].index;
		return suffixArr;
	}*/
	private static long pow(long a, long b, long c) {
		if (b == 0)
			return 1;
		long p = pow(a, b / 2, c);
		p = (p * p) % c;
		return (b % 2 == 0) ? p : (a * p) % c;
	}
	
	private static class Pair implements Comparable<Pair> {
		int x;
		int y;
		int z;
		public Pair(int a,int b,int c) {
			x=a;y=b;z=c;
		}
		@Override
		public int compareTo(Pair arg0) {
			return (this.x!=arg0.x)?(this.x-arg0.x):((this.y!=arg0.y)?(this.y-arg0.y):(this.z-arg0.z));
		}
	}

	private static int gcd(int a1, int a2) {
		if (a2 == 0)
			return a1;
		return gcd(a2, a1 % a2);
	}

	private static long max(long a, long b) {
		if (a > b)
			return a;
		return b;
	}

	private static long min(long a, long b) {
		if (a < b)
			return a;
		return b;
	}

	public static void main(String[] args) throws Exception {
		InputReader(System.in);
		pw = new PrintWriter(System.out);
		soln();
		pw.close();
	}

	public static void InputReader(InputStream stream1) {
		stream = stream1;
	}

	private static boolean isWhitespace(int c) {
		return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
	}

	private static boolean isEndOfLine(int c) {
		return c == '\n' || c == '\r' || c == -1;
	}

	private static int read() {
		if (numChars == -1)
			throw new InputMismatchException();
		if (curChar >= numChars) {
			curChar = 0;
			try {
				numChars = stream.read(buf);
			} catch (IOException e) {
				throw new InputMismatchException();
			}
			if (numChars <= 0)
				return -1;
		}
		return buf[curChar++];
	}

	private static int nextInt() {
		int c = read();
		while (isSpaceChar(c))
			c = read();
		int sgn = 1;
		if (c == '-') {
			sgn = -1;
			c = read();
		}
		int res = 0;
		do {
			if (c < '0' || c > '9')
				throw new InputMismatchException();
			res *= 10;
			res += c - '0';
			c = read();
		} while (!isSpaceChar(c));
		return res * sgn;
	}

	private static long nextLong() {
		int c = read();
		while (isSpaceChar(c))
			c = read();
		int sgn = 1;
		if (c == '-') {
			sgn = -1;
			c = read();
		}
		long res = 0;
		do {
			if (c < '0' || c > '9')
				throw new InputMismatchException();
			res *= 10;
			res += c - '0';
			c = read();
		} while (!isSpaceChar(c));
		return res * sgn;
	}

	private static String nextToken() {
		int c = read();
		while (isSpaceChar(c))
			c = read();
		StringBuilder res = new StringBuilder();
		do {
			res.appendCodePoint(c);
			c = read();
		} while (!isSpaceChar(c));
		return res.toString();
	}

	private static String nextLine() {
		int c = read();
		while (isSpaceChar(c))
			c = read();
		StringBuilder res = new StringBuilder();
		do {
			res.appendCodePoint(c);
			c = read();
		} while (!isEndOfLine(c));
		return res.toString();
	}

	private static int[] nextIntArray(int n) {
		int[] arr = new int[n];
		for (int i = 0; i < n; i++) {
			arr[i] = nextInt();
		}
		return arr;
	}

	private static long[] nextLongArray(int n) {
		long[] arr = new long[n];
		for (int i = 0; i < n; i++) {
			arr[i] = nextLong();
		}
		return arr;
	}

	private static void pArray(int[] arr) {
		for (int i = 0; i < arr.length; i++) {
			System.out.print(arr[i] + " ");
		}
		System.out.println();
		return;
	}

	private static void pArray(long[] arr) {
		for (int i = 0; i < arr.length; i++) {
			System.out.print(arr[i] + " ");
		}
		System.out.println();
		return;
	}

	private static boolean isSpaceChar(int c) {
		if (filter != null)
			return filter.isSpaceChar(c);
		return isWhitespace(c);
	}

	private interface SpaceCharFilter {
		public boolean isSpaceChar(int ch);
	}
}