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 test {
    int INF = (int)1e9;
    long MOD = 1000000007;
    
    
    
    int[] r(int[] p, int c) {
        int[] x = Arrays.copyOf(p, 4);
        x[0] -= x[2];
        x[1] -= x[3];
        x = rx(x, c);
        x[2] = p[2];
        x[3] = p[3];
        x[0] += x[2];
        x[1] += x[3];
        return x;
    }
    
    int[] rx(int[] p, int c) {
        int[] rs = new int[4];
        if(c==0) {
            rs = Arrays.copyOf(p, 4);
        } else {
            rs[0] = -p[1];
            rs[1] = p[0];
            rs = r(rs, c-1);
        }
        return rs;
    }
    
    long d(int[] a, int[] b) {
        long rs = 0;
        int i = 0;
        rs += (a[i]-b[i])*(a[i]-b[i]);
        i = 1;
        rs += (a[i]-b[i])*(a[i]-b[i]);
        return rs;
    }
    
    boolean gg(int[][] x, int i) {
        long[] a = new long[3];
        int pt = 0;
        for(int j=0; j<4; j++) if(j!=i) {
            a[pt++] = d(x[i], x[j]);
        }
        Arrays.sort(a);
        if(a[0]==0) return false;
        if(a[0]!=a[1]) return false;
        if(2*a[0]==a[2]) return true;
        return false;
    }
    
    boolean check(int[][] x) {
        boolean rs = true;
        for(int i=0; i<4; i++)
            rs = rs && gg(x, i);
        return rs;
//        int[][] p = new int[4][];
//        for(int i=0; i<4; i++) {
//            p[i] = Arrays.copyOf(x[i], 2);
//        }
//        Arrays.sort(p, new Comparator<int[]>(){
//            public int compare(int[] x, int[] y) {
//                if(x[0]!=y[0]) return x[0]-y[0];
//                return x[1]-y[1];
//            }
//        });
//        if(p[0][0]!=p[1][0] || p[2][0]!=p[3][0]) return false;
//        if(p[0][1]!=p[2][1] || p[1][1]!=p[3][1]) return false;
//        if((p[1][1]-p[0][1]) != (p[2][0]-p[0][0])) return false;
//        if(p[1][1]==p[0][1]) return false;
//        return true;
    }
    
    int go(int[][] x, int[] c) {
        int rs = INF;
        for(int i=0; i<4; i++) {
            for(int j=0; j<4; j++) {
                for(int k=0; k<4; k++) {
                    for(int l=0; l<4; l++) {
                        int[][] p = new int[4][];
                        for(int id=0; id<4; id++) {
                            p[id] = Arrays.copyOf(x[id], 4);
                        }
                        p[0] = r(p[0], i);
                        p[1] = r(p[1], j);
                        p[2] = r(p[2], k);
                        p[3] = r(p[3], l);
                        
                        if(check(p)) {
                            rs = Math.min(rs, i+j+k+l);
                        }
                    }
                }
            }
        }
        if(rs==INF) return -1;
        return rs;
    }
    
    void solve(InputReader in, PrintWriter out) throws IOException {
        int n = in.nextInt();
        for(int j=0; j<n; j++) {
            int[][] p = new int[4][4];
            for(int i=0; i<4; i++) {
                p[i][0] = in.nextInt();
                p[i][1] = in.nextInt();
                p[i][2] = in.nextInt();
                p[i][3] = in.nextInt();
//                if(i==0) {
//                    int[] x = Arrays.copyOf(p[0], 4);
//                    for(int k=0; k<5; k++) {
//                        int[] y = Arrays.copyOf(x, 4);
//                        show(r(y, k));
//                    }
//                }
            }
            int rs = go(p, new int[4]);
            out.println(rs);
        }
    }
    
    
    public static void main(String[] args) throws IOException {
        if(args.length>0 && args[0].equalsIgnoreCase("d")) {
            DEBUG_FLAG = true;
        }
        InputReader in = new InputReader();
        PrintWriter out = new PrintWriter(System.out);
        int t = 1;//in.nextInt();
        long start = System.nanoTime();
        while(t-->0) {
            new test().solve(in, out);
        }
        long end = System.nanoTime();
        debug("\nTime: " + (end-start)/1e6 + " \n\n");
        out.close();
    }
    
    static boolean DEBUG_FLAG = false;
    static void debug(String s) {
        if(DEBUG_FLAG) System.out.print(s);
    }
    
    public static void show(Object... o) {
        System.out.println(Arrays.deepToString(o));
    }
    
    static class InputReader {
        static BufferedReader br;
        static StringTokenizer st;
    
        public InputReader() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }
        
        String next() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }
        
        int nextInt() {
            return Integer.parseInt(next());
        }
        
        long nextLong() {
            return Long.parseLong(next());
        }
        
        double nextDouble() {
            return Double.parseDouble(next());
        }
    }
}