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.*;
import java.util.*;

public class C {
	FastScanner in = new FastScanner(System.in);
	PrintWriter out = new PrintWriter(System.out);

	int calc(int bit) {
		int res = 0;
		while (bit > 0) {
			res += bit % 4;
			bit /= 4;
		}
		
		return res;
	}
	
	int[][] comb1 = new int[][]{{0, 1}, {0, 1}, {0, 2}, {0, 2}, {0, 3}, {0, 3}};
	int[][] comb2 = new int[][]{{2, 3}, {3, 2}, {1, 3}, {3, 1}, {1, 2}, {2, 1}};
	
	int flag;
	boolean isOk(int[] x, int[] y) {
		for (int i = 0; i < 4; i++) 
			for (int j = i + 1; j < 4; j++)
				if (x[i] == x[j] && y[i] == y[j]) return false;
		
		for (int i = 0; i < comb1.length; i++) {
			int a = comb1[i][0], b = comb1[i][1];
			int c = comb2[i][0], d = comb2[i][1];
		
			long vx1 = x[a] - x[b], vy1 = y[a] - y[b];
			long vx2 = x[b] - x[c], vy2 = y[b] - y[c];
			long vx3 = x[c] - x[d], vy3 = y[c] - y[d];
			long vx4 = x[d] - x[a], vy4 = y[d] - y[a];
			
			if (vx1 * vx2 + vy1 * vy2 == 0 && vx3 * vx4 + vy3 * vy4 == 0 &&
				vx1 * vx1 + vy1 * vy1 == vx2 * vx2 + vy2 * vy2 && 
				vx3 * vx3 + vy3 * vy3 == vx4 * vx4 + vy4 * vy4) return true;
		}
		return false;
	}
	
	public void run() {
		int n = in.nextInt();
		
		for (int timeN = 0; timeN < n; timeN++) {
			int[] x = new int[4], y = new int[4];
			int[] a = new int[4], b = new int[4];
			
			for (int i = 0; i < 4; i++) {
				x[i] = in.nextInt();
				y[i] = in.nextInt();
				a[i] = in.nextInt();
				b[i] = in.nextInt();
			}
			
			int[] origX = new int[4], origY = new int[4];
			int[] origA = new int[4], origB = new int[4];
			for (int i = 0; i < 4; i++) {
				origX[i] = x[i];
				origY[i] = y[i];
				origA[i] = a[i];
				origB[i] = b[i];
			}
			
			int res = Integer.MAX_VALUE;
			for (int i = 0; i < 256; i++) {
				flag = i;
				int bit = i;
				for (int j = 0; j < 4; j++) {
					int rotateN = bit % 4;
					for (int k = 0; k < rotateN; k++) {
						int temp = x[j];
						x[j] = -y[j] + b[j] + a[j];
						y[j] = -a[j] + temp + b[j];
					}
					bit /= 4;
				}
				
				if (isOk(x, y)) {
					res = Math.min(res, calc(i));
				}
				
				for (int j = 0; j < 4; j++) {
					x[j] = origX[j];
					y[j] = origY[j];
					a[j] = origA[j];
					b[j] = origB[j];
				}				
			}
			
			System.out.println(res == Integer.MAX_VALUE ? -1 : res);
		}
		out.close();
	}

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

	public void mapDebug(int[][] a) {
		System.out.println("--------map display---------");

		for (int i = 0; i < a.length; i++) {
			for (int j = 0; j < a[i].length; j++) {
				System.out.printf("%3d ", a[i][j]);
			}
			System.out.println();
		}

		System.out.println("----------------------------");
		System.out.println();
	}

	public void debug(Object... obj) {
		System.out.println(Arrays.deepToString(obj));
	}

	class FastScanner {
		private InputStream stream;
		private byte[] buf = new byte[1024];
		private int curChar;
		private int numChars;

		public FastScanner(InputStream stream) {
			this.stream = stream;
			//stream = new FileInputStream(new File("dec.in"));

		}

		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++];
		}

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

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

		int nextInt() {
			return Integer.parseInt(next());
		}

		int[] nextIntArray(int n) {
			int[] array = new int[n];
			for (int i = 0; i < n; i++)
				array[i] = nextInt();

			return array;
		}

		long nextLong() {
			return Long.parseLong(next());
		}

		long[] nextLongArray(int n) {
			long[] array = new long[n];
			for (int i = 0; i < n; i++)
				array[i] = nextLong();

			return array;
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}

		double[] nextDoubleArray(int n) {
			double[] array = new double[n];
			for (int i = 0; i < n; i++)
				array[i] = nextDouble();

			return array;
		}

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

		String[] nextStringArray(int n) {
			String[] array = new String[n];
			for (int i = 0; i < n; i++)
				array[i] = next();

			return array;
		}

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

