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.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.io.FilterInputStream;
import java.io.BufferedInputStream;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        ScanReader in = new ScanReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        CCaptainMarmot solver = new CCaptainMarmot();
        solver.solve(1, in, out);
        out.close();
    }

    static class CCaptainMarmot {
        int[] assss;
        long ans;
        points[] arr;

        public void solve(int testNumber, ScanReader in, PrintWriter out) {
            int n = in.scanInt();
            arr = new points[4 * n];
            assss = new int[4];
            for (int i = 0; i < 4 * n; i++) {
                arr[i] = new points(in.scanInt(), in.scanInt(), in.scanInt(), in.scanInt());
            }


            int k = 0;

            for (int i = 0; i < n; i++) {
                Arrays.fill(assss, -1);
                ans = Long.MAX_VALUE;

                Arrays.fill(assss, -1);
                assss[0] = 0;
                DFS(0, k);

                Arrays.fill(assss, -1);
                assss[0] = 1;
                DFS(0, k);

                Arrays.fill(assss, -1);
                assss[0] = 2;
                DFS(0, k);

                Arrays.fill(assss, -1);
                assss[0] = 3;
                DFS(0, k);

                if (ans == Long.MAX_VALUE) {
                    out.println(-1);
                } else {
                    out.println(ans);
                }
                k += 4;
            }
        }

        boolean DFS(int index, int kk) {
            if (index == 3) {
                Point pp[] = new Point[4];
                for (int j = 0; j < 4; j++) {
                    pp[j] = new Point(arr[kk + j].com[assss[j]][0], arr[kk + j].com[assss[j]][1]);
                }
                if (isSquare(pp[0], pp[1], pp[2], pp[3])) {
                    long s = 0;
                    for (int i = 0; i < 4; i++) {
                        s += (assss[i]);
                    }
                    ans = Math.min(ans, s);
                    return true;
                }
                return false;
            }

            boolean f = false;
            for (int i = 0; i <= 3; i++) {
                assss[index + 1] = i;
                boolean k = DFS(index + 1, kk);
                f |= k;
                if (k) return true;
                assss[index + 1] = -1;
            }
            return f;
        }

        int[] find(int x, int y, int ax, int ay) {
            x -= ax;
            y -= ay;
            int nx = -y;
            int ny = x;
            nx += ax;
            ny += ay;
            return new int[]{nx, ny};
        }

        long distSq(Point p, Point q) {
            return (p.x - q.x) * (p.x - q.x) + (p.y - q.y) * (p.y - q.y);
        }

        boolean isSquare(Point p1, Point p2, Point p3, Point p4) {
            if (p1.x == p2.x && p2.x == p3.x && p3.x == p4.x && p1.y == p2.y && p2.y == p3.y && p3.y == p4.y)
                return false;
            long d2 = distSq(p1, p2);
            long d3 = distSq(p1, p3);
            long d4 = distSq(p1, p4);
            if (d2 == d3 && 2 * d2 == d4 && 2 * d2 == distSq(p2, p3)) {
                long d = distSq(p2, p4);
                return (d == distSq(p3, p4) && d == d2);
            }
            if (d3 == d4 && 2 * d3 == d2 && 2 * d3 == distSq(p3, p4)) {
                long d = distSq(p2, p3);
                return (d == distSq(p2, p4) && d == d3);
            }
            if (d2 == d4 && 2 * d2 == d3 && 2 * d2 == distSq(p2, p4)) {
                long d = distSq(p2, p3);
                return (d == distSq(p3, p4) && d == d2);
            }
            return false;
        }

        class points {
            int x;
            int y;
            int ax;
            int ay;
            int[][] com;

            public points(int x, int y, int ax, int ay) {
                this.x = x;
                this.y = y;
                this.ax = ax;
                this.ay = ay;
                com = new int[4][2];
                com[0][0] = this.x;
                com[0][1] = this.y;

                int temp[] = find(x, y, ax, ay);
                com[1][0] = temp[0];
                com[1][1] = temp[1];

                temp = find(com[1][0], com[1][1], ax, ay);
                com[2][0] = temp[0];
                com[2][1] = temp[1];


                temp = find(com[2][0], com[2][1], ax, ay);
                com[3][0] = temp[0];
                com[3][1] = temp[1];

            }

        }

        class Point {
            long x;
            long y;

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

        }

    }

    static class ScanReader {
        private byte[] buf = new byte[4 * 1024];
        private int INDEX;
        private BufferedInputStream in;
        private int TOTAL;

        public ScanReader(InputStream inputStream) {
            in = new BufferedInputStream(inputStream);
        }

        private int scan() {
            if (INDEX >= TOTAL) {
                INDEX = 0;
                try {
                    TOTAL = in.read(buf);
                } catch (Exception e) {
                    e.printStackTrace();
                }
                if (TOTAL <= 0) return -1;
            }
            return buf[INDEX++];
        }

        public int scanInt() {
            int I = 0;
            int n = scan();
            while (isWhiteSpace(n)) n = scan();
            int neg = 1;
            if (n == '-') {
                neg = -1;
                n = scan();
            }
            while (!isWhiteSpace(n)) {
                if (n >= '0' && n <= '9') {
                    I *= 10;
                    I += n - '0';
                    n = scan();
                }
            }
            return neg * I;
        }

        private boolean isWhiteSpace(int n) {
            if (n == ' ' || n == '\n' || n == '\r' || n == '\t' || n == -1) return true;
            else return false;
        }

    }
}

