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.math.*;
import java.io.*;
import java.awt.*;
import java.awt.geom.AffineTransform;

public class TaskA {
    static FastReader in = new FastReader(new BufferedReader(new InputStreamReader(System.in)));
    static PrintWriter out = new PrintWriter(System.out);
    static final int maxn = (int)1e5 + 11;
    static int inf = (1<<30) - 1;
    static int mod = (int)1e9 + 7;
    
    static double [] rotate(double x, double y, double ax, double ay, int angle){
        double[] pt = {x, y};
        AffineTransform.getRotateInstance(Math.toRadians(angle), ax, ay).transform(pt, 0, pt, 0, 1);  
        return pt;
    }
    
    static double dist(double a[], double b[]){
        return (b[0] - a[0])*(b[0] - a[0]) + (b[1] - a[1])*(b[1] - a[1]);
    }
    
    static boolean check(double pti[], double ptj[], double ptk[], double ptt[]){
        double a[][] = new double[4][2];
        a[0] = pti;
        a[1] = ptj;
        a[2] = ptk;
        a[3] = ptt;

        for (int i=0;i<4;i++){
            for (int j=0;j<4;j++){
                if ( i == j) continue;
                for (int k=0;k<4;k++){
                    if ( k == i || k == j ) continue;
                    for (int t=0;t<4;t++){
                        if ( t == i || t == j || t == k ) continue;

                        if ( dist(a[i], a[j]) == dist(a[j], a[k]) && dist(a[j], a[k]) == dist(a[k], a[t]) 
                        && dist(a[k], a[t]) == dist(a[i], a[j]) && dist(a[i], a[k]) == dist(a[j], a[t]) && dist(a[i], a[j]) == dist(a[k], a[t]) 
                        && dist(a[i], a[j]) > 0 && dist(a[i], a[k]) > 0 ){
                            double midx = (a[i][0] + a[k][0])/2.0;
                            double midy = (a[i][1] + a[k][1])/2.0;

                            double pt0 [] = rotate(a[j][0], a[j][1], midx, midy, 90*3);
                            if ( pt0[0] != a[i][0] || pt0[1] != a[i][1] ) continue;

                            double pt1 [] = rotate(a[t][0], a[t][1], midx, midy, 90);
                            if ( pt1[0] != a[i][0] || pt1[1] != a[i][1] ) continue;
                            
                            double pt2 [] = rotate(a[k][0], a[k][1], midx, midy, 90*2);
                            if ( pt2[0] != a[i][0] || pt2[1] != a[i][1] ) continue;
                            return true;
                        }
                    }
                }
            }
        }
        return false;
    }
    
    /*
1
1 1 0 0
-1 1 0 0
-1 1 0 0
-1 1 0 0

     */
    
    public static void main(String[] args) throws Exception {
        int n = in.nextInt();
        
        int x[] = new int[4];
        int y[] = new int[4];
        int ax[] = new int[4];
        int ay[] = new int[4];
        
        for (int iii=0;iii<n;iii++){
            for (int j=0;j<4;j++){
                x[j] = in.nextInt();
                y[j] = in.nextInt();
                ax[j] = in.nextInt();
                ay[j] = in.nextInt();
            }
            int mini = inf;
            for (int i=0;i<4;i++){
                double pti [] = rotate(x[0], y[0], ax[0], ay[0], 90*i);
                for (int j=0;j<4;j++){
                    double ptj [] = rotate(x[1], y[1], ax[1], ay[1], 90*j);
                    for (int k=0;k<4;k++){
                        double ptk [] = rotate(x[2], y[2], ax[2], ay[2], 90*k);
                        for (int t=0;t<4;t++){
                            double ptt [] = rotate(x[3], y[3], ax[3], ay[3], 90*t);
                            
                            if ( check(pti, ptj, ptk, ptt) ){
                                mini = Math.min(mini, i+j+k+t);
                            }
                        }
                    }
                }
            }
            
            if ( mini == inf ){
                out.println(-1);
            }
            else
                out.println(mini);
            
        }
        
        
        
        out.close();
    }
}

class Pair<F, S> {
    public final F first;
    public final S second;

    public Pair(F first, S second) {
        this.first = first;
        this.second = second;
    }

    @Override
    public boolean equals(Object o) {
        if (!(o instanceof Pair)) {
            return false;
        }
        Pair<?, ?> p = (Pair<?, ?>) o;
        return Objects.equals(p.first, first) && Objects.equals(p.second, second);
    }

    @Override
    public int hashCode() {
        return (first == null ? 0 : first.hashCode()) ^ (second == null ? 0 : second.hashCode());
    }

    public static <A, B> Pair <A, B> create(A a, B b) {
        return new Pair<A, B>(a, b);
    }
}

class FastReader {

    BufferedReader bf;
    StringTokenizer tk = null;
    String DELIM = " ";

    public FastReader(BufferedReader bf) {
        this.bf = bf;
    }

    public String nextToken() throws Exception {

        if(tk==null || !tk.hasMoreTokens()) {
            tk = new StringTokenizer(bf.readLine(),DELIM);
        }
        return tk.nextToken();
    }

    public int nextInt() throws Exception {
        return Integer.parseInt(nextToken());
    }

    public long nextLong() throws Exception {
        return Long.parseLong(nextToken());
    }

    public double nextDouble() throws Exception {
        return Double.parseDouble(nextToken());
    }
}