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.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Collections;

public class Main{

    public static int[] readInts(String cad) {
        String read[] = cad.split(" ");
        int res[] = new int[read.length];
        for (int i = 0; i < read.length; i++) {
            res[i] = Integer.parseInt(read[i]);
        }
        return res;
    }

    public static long[] readLongs(String cad) {
        String read[] = cad.split(" ");
        long res[] = new long[read.length];
        for (int i = 0; i < read.length; i++) {
            res[i] = Long.parseLong(read[i]);
        }
        return res;
    }

    static void printArrayInt(int[] array) {
        if (array == null || array.length == 0)
            return;
        for (int i = 0; i < array.length; i++) {
            if (i > 0)
                System.out.print(" ");
            System.out.print(array[i]);
        }
        System.out.println();
    }

    static void printMatrixInt(int[][] array) {
        if (array == null || array.length == 0)
            return;
        for (int i = 0; i < array.length; i++) {
            for (int j = 0; j < array[0].length; j++) {
                if (j > 0)
                    System.out.print(" ");
                System.out.print(array[i][j]);
            }
            System.out.println();
        }

    }

    public static int nextInt(String cad) throws IOException {
        return Integer.parseInt(cad);
    }

    public static double nextDouble(String cad) throws IOException {
        return Double.parseDouble(cad);
    }

    public static BufferedReader in;

    public static class Node {
        Point p[];
        Point piv;

        public Node(Point t) {
            this.p = new Point[4];
            this.piv = t;
        }

    }

    public static class Point implements Comparable<Point> {
        int x, y;
        int w;

        public Point(int x, int y, int w) {
            this.x = x;
            this.y = y;
            this.w = w;
        }

        public Point(int x, int y) {
            this.x = x;
            this.y = y;
        }

        @Override
        public int compareTo(Point o) {
            if (x == o.x)
                return y - o.y;
            else {
                return x - o.x;
            }

        }

    }

    public static boolean iguales(Point a, Point b) {
        if (a.x == b.x && a.y == b.y)
            return true;
        return false;
    }

    public static Point girar(Point a, Point b, int num) {
        if (num > 1)
            b = girar(a, b, num - 1);

        Point res = null;
        int rX = Math.abs(a.x - b.x);
        int rY = Math.abs(a.y - b.y);

        if (a.x >= b.x && a.y >= b.y) {
            res = new Point(a.x + rY, a.y - rX, 1);
        } else if (a.x <= b.x && a.y >= b.y) {
            res = new Point(a.x + rY, a.y + rX, 1);
        } else if (a.x <= b.x && a.y <= b.y) {
            res = new Point(a.x - rY, a.y + rX, 1);
        } else if (a.x >= b.x && a.y <= b.y) {
            res = new Point(a.x - rY, a.y - rX, 1);
        }
        return res;
    }

    public static double dist(Point a, Point b) {
        return Math.sqrt(Math.pow(a.x - b.x, 2) + Math.pow(a.y - b.y, 2));
    }

    public static int cmp(final double x, final double y, final double eps) {
        return (x <= y + eps) ? (x + eps < y) ? -1 : 0 : 1;
    }

    public static boolean ok(Point a, Point b, Point c, Point d) {
        ArrayList<Point> lista = new ArrayList<Point>();
        lista.add(a);
        lista.add(b);
        lista.add(c);
        lista.add(d);
        Collections.sort(lista);

        ArrayList<Double> l = new ArrayList<Double>();
        for (int i = 0; i < 4; i++) {
            for (int j = 0; j < i; j++) {
                l.add(dist(lista.get(i), lista.get(j)));
            }
        }
        Collections.sort(l);
        if (cmp(l.get(0), l.get(3), 00000.1) != 0) {
            return false;
        }
        if (cmp(l.get(0),0.0, 00000.1) == 0)
            return false;
        if (cmp(l.get(4), l.get(5), 00000.1) != 0)
            return false;

        return true;

    }

    public static void main(String[] args) throws IOException {

        File f = new File("entrada");
        if (f.exists()) {
            in = new BufferedReader(new FileReader(f));
        } else
            in = new BufferedReader(new InputStreamReader(System.in));

        int n = nextInt(in.readLine());
        for (int i = 0; i < n; i++) {
            Node nodes[] = new Node[4];
            for (int j = 0; j < 4; j++) {
                int d[] = readInts(in.readLine());
                Point r = new Point(d[2], d[3], 0);
                Point s = new Point(d[0], d[1], 0);
                nodes[j] = new Node(r);
                nodes[j].p[0] = s;
                for (int k = 1; k < 4; k++) {
                    nodes[j].p[k] = girar(r, s, 4 - k);
                    nodes[j].p[k].w = 4 - k;
                }
            }

            int max = Integer.MAX_VALUE;
            for (int a = 0; a < 4; a++) {
                for (int b = 0; b < 4; b++) {
                    for (int c = 0; c < 4; c++) {
                        for (int d = 0; d < 4; d++) {
                            if (ok(nodes[0].p[a], nodes[1].p[b], nodes[2].p[c],
                                    nodes[3].p[d])) {
                                max = Math.min(max, nodes[0].p[a].w
                                        + nodes[1].p[b].w + nodes[2].p[c].w
                                        + nodes[3].p[d].w);
                            }
                        }
                    }
                }
            }
            if (max == Integer.MAX_VALUE) {
                System.out.println("-1");
            } else
                System.out.println(max);
        }

    }
}
