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.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;

public class CF271C {
	static InputReader input;
	
	public static final int INFTY = 1000000 + 5;
		
	public static void main (String[] args) {
//		pos testHome = new pos(0,1);
//		pos testCur = new pos(2,2);
//		pos r1 = rotate(testCur, testHome);
//		pos r2 = rotate(r1, testHome);
//		pos r3 = rotate(r2, testHome);
//		pos r4 = rotate(r3, testHome);
//		
//		boolean testSq1 = checkSquare(new pos(1,1), new pos(-1, 1), new pos(-1, -1), new pos(1, -1));
//		boolean testSq2 = checkSquare(new pos(1,0), new pos(0, 1), new pos(-1, 0), new pos(0, -1));
//		boolean testSq3 = checkSquare(new pos(2,0), new pos(0, 1), new pos(-1, -1), new pos(1, -2));
//		
//		boolean testSq4 = checkSquare(new pos(1,1), new pos(-1, 1), new pos(-1, -1), new pos(2, -1));
//		boolean testSq5 = checkSquare(new pos(2,0), new pos(0, 1), new pos(-1, 0), new pos(0, -1));
//		boolean testSq6 = checkSquare(new pos(3,0), new pos(0, 1), new pos(-1, -1), new pos(1, -2));
		
		
		input = new InputReader(System.in);
		PrintWriter out = new PrintWriter(System.out);
		
		pos[][] original = new pos[4][4];
		pos[] home = new pos[4];
		
		int n = input.nextInt();
		
		for (int i = 0; i < n; i++) {
			int min = INFTY;
			
			for (int j = 0; j < 4; j++) {
				original[j][0] = new pos(input.nextInt(), input.nextInt());
				home[j] = new pos(input.nextInt(), input.nextInt());
				
				for (int r = 1; r <= 3; r++) {
					original[j][r] = rotate(original[j][r-1], home[j]);
				}								
			}
			
			for (int p = 0; p < 4; p++) {				
				for (int q = 0; q < 4; q++) {
					for (int r = 0; r < 4; r++) {
						for (int s = 0; s < 4; s++) {
							if (checkSquare(original[0][p], original[1][q], 
									original[2][r], original[3][s])) {
								min = Math.min(p+q+r+s, min);
							}
						}
					}
				}
			}
			
			if (min < INFTY) out.println(min);
			else out.println("-1");
		}			
		
		out.close();
	}
	
	public static pos rotate(pos cur, pos home) {
		long xIncr = cur.i - home.i;
		long yIncr = cur.j - home.j;
		return new pos(home.i - yIncr, home.j + xIncr);
	}
	
	public static boolean checkSquare(pos p1, pos p2, pos p3, pos p4) {
		pos vec1 = p2.sub(p1);
		pos vec2 = p3.sub(p1);
		pos vec3 = p4.sub(p1);
		
		double len1 = vec1.len();
		double len2 = vec2.len();
		double len3 = vec3.len();
//		boolean eq = (len1 == len3);
//		pos vec13 = vec1.add(vec3);
//		boolean eqvec = vec2.equals(vec1.add(vec3));
		
		
		return (len1 > 0 && len2 > 0 && len3 > 0) && 
				((vec1.len() == vec2.len() && vec1.dot(vec2) == 0 && vec3.equals(vec1.add(vec2))) || 
				(vec1.len() == vec3.len() && vec1.dot(vec3) == 0 && vec2.equals(vec1.add(vec3))) ||
				(vec2.len() == vec3.len() && vec2.dot(vec3) == 0 && vec1.equals(vec2.add(vec3))));
	}
	
	static class pos {
		public long i;
		public long j;
		
		public pos(long i, long j) {
			super();
			this.i = i;
			this.j = j;
		}

		@Override
		public int hashCode() {
			final int prime = 31;
			int result = 1;
			result = prime * result + (int) (i ^ (i >>> 32));
			result = prime * result + (int) (j ^ (j >>> 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;
			pos other = (pos) obj;
			if (i != other.i)
				return false;
			if (j != other.j)
				return false;
			return true;
		}

		public String toString() {
			return "(" + i + "," + j + ")";
		}
		
		public pos add (pos that) {
			return new pos(this.i + that.i, this.j + that.j);
		}
		
		public pos sub (pos that) {
			return new pos(this.i - that.i, this.j - that.j);
		}
		
		public double len () {
			return Math.sqrt(this.i * this.i + this.j * this.j);
		}
		
		public long dot(pos that) {
			return this.i * that.i + this.j * that.j;
		}
	}
	
	static class InputReader {
		private InputStream stream;
		private byte[] buf = new byte[1024];
		private int curChar;
		private int numChars;
		private SpaceCharFilter filter;

		public InputReader(InputStream stream) {
			this.stream = stream;
		}
		
		
		public 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++];
		}

		public 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;
		}

		public 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;
		}
		

		public 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();
		}

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

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

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