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.*;
    import java.io.*;
 
     public class CodeForces {
        
        
        public static void main(String[] args) throws IOException {
            Reader.init(System.in);
            PrintWriter writer = new PrintWriter(System.out);
            
//            
//            if(true){
//                Point p= new Point(1,1);
//                p.rotate(new Point(0, 0), 90);
//                System.out.println(p);
//                return;
//            }
            int n = Reader.nextInt();
            
            
            int th[] = {0, 90, 180, 270};
            
            out : for (int i = 0; i < n; i++) {
                Point arr[][] = new Point[4][2];
                
                for (int j = 0; j < 4; j++) {
                    arr[j][0] = new Point(Reader.nextInt(), Reader.nextInt());
                    arr[j][1] = new Point(Reader.nextInt(), Reader.nextInt());
                }
                
                Point newPoints[] = new Point[4];
                int min = (int) 100;
                
                for (int j = 0; j < 4; j++) {
                    for (int k = 0; k < 4; k++) {
                        for (int l = 0; l < 4; l++) {
                            for (int m = 0; m < 4; m++) {
                               
                               newPoints[0] = arr[0][0].clone();
                               newPoints[1] = arr[1][0].clone();
                               newPoints[2] = arr[2][0].clone();
                               newPoints[3] = arr[3][0].clone();
                               
                               newPoints[0].rotate(arr[0][1], th[j]);
                               newPoints[1].rotate(arr[1][1], th[k]);
                               newPoints[2].rotate(arr[2][1], th[l]);
                               newPoints[3].rotate(arr[3][1], th[m]);
                               
                                if(check(newPoints)){
                                    min = Math.min(min, j + k + l + m);
                                }
                            }
                        }
                    }
                }
                
                if(min == 100)
                    writer.println(-1);
                else
                    writer.println(min);
            }
            
            writer.close();
        }
        
        static boolean check(Point arr[]){
            HashSet<Double> set = new HashSet<Double>();
            
            for (int i = 0; i < arr.length; i++) {
                for (int j = 0; j < arr.length; j++) if(i != j){
                    set.add((arr[i].x - arr[j].x) * (arr[i].x - arr[j].x) + (arr[i].y - arr[j].y) * (arr[i].y - arr[j].y));
                }
            }
            
            if(set.size() > 2)
                return false;
            
            for(double x : set){
                if(x == 0)
                    return false;
            }
            
            return true;
        }
        
    }
    
    class  Edge implements Comparable<Edge>{
 
        int to;
        int from;
        int cost;
        
        Edge(int a, int b, int c){
            from = a;
            to = b;
            cost = c;
        }
 
        @Override
        public int compareTo(Edge t) {
            return t.cost - cost;
        }
    }
 
 
class Point{
    double x, y;

    public Point(double x, double y) {
        this.x = x;
        this.y = y;
    }
        
            
    public Point clone(){
        return new Point(x, y);
    }
    

    public void rotate(Point org, int th){
        this.x -= org.x;
        this.y -= org.y;

        double c = (int)Math.cos(Math.toRadians(th));
        double s = (int)Math.sin(Math.toRadians(th));

        double newX = this.x * c - this.y * s;
        double newY = this.x * s + this.y * c;

        this.x = newX + org.x;
        this.y = newY + org.y;
    }

    @Override
    public String toString() {
        return this.x + ", " + this.y;
    }
    
    
}
 
 
    class Reader {
 
        static BufferedReader reader;
        static StringTokenizer tokenizer;
 
        public static int pars(String x) {
            int num = 0;
            int i = 0;
            if (x.charAt(0) == '-') {
                i = 1;
            }
            for (; i < x.length(); i++) {
                num = num * 10 + (x.charAt(i) - '0');
            }
 
            if (x.charAt(0) == '-') {
                return -num;
            }
 
            return num;
        }
 
        static void init(InputStream input) {
            reader = new BufferedReader(
                    new InputStreamReader(input));
            tokenizer = new StringTokenizer("");
        }
 
        static void init(FileReader input) {
            reader = new BufferedReader(input);
            tokenizer = new StringTokenizer("");
        }
 
        static String next() throws IOException {
            while (!tokenizer.hasMoreTokens()) {
                tokenizer = new StringTokenizer(
                        reader.readLine());
            }
            return tokenizer.nextToken();
        }
 
        static int nextInt() throws IOException {
            return pars(next());
        }
 
        static long nextLong() throws IOException {
            return Long.parseLong(next());
        }
 
        static double nextDouble() throws IOException {
            return Double.parseDouble(next());
        }
    }