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.Arrays;

public class Main {
    private final Reader reader;

    private final Writer writer;

    public static void main(String[] args) throws IOException {
        new Main().solve();

    }
    private void solve() throws IOException {
        int N = reader.nextUnsignedInt();
        int x[] = new int[4];
        int y[] = new int[4];
        int a[] = new int[4];
        int b[] = new int[4];
        int positions[][][] = new int[4][4][2];
        for (int n = 0; n < N; n++) {
            for (int f = 0; f < 4; f++) {
                x[f] = reader.nextInt();
                y[f] = reader.nextInt();
                a[f] = reader.nextInt();
                b[f] = reader.nextInt();

                positions[f][0][0] = x[f];
                positions[f][0][1] = y[f];
                int X = x[f] - a[f];
                int Y = y[f] - b[f];

                positions[f][1][0] = a[f] - Y;
                positions[f][1][1] = b[f] + X;

                positions[f][2][0] = a[f] - X;
                positions[f][2][1] = b[f] - Y;

                positions[f][3][0] = a[f] + Y;
                positions[f][3][1] = b[f] - X;
            }

            int moves = moves(positions, a, b);
            writer.print(moves + "\n");
        }


        writer.flush();
    }

    private int moves(int[][][] positions, int[] a, int[] b) {
        int min = 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 (square(positions[0][A], positions[1][B], positions[2][C], positions[3][D])) {
                            min = Math.min(min, numberOfMoves(positions, a, b, positions[0][A], positions[1][B], positions[2][C], positions[3][D]));
                        }
                    }
                }
            }
        }
        return min == Integer.MAX_VALUE ? -1 : min;
    }

    private boolean square(int[] p1, int[] p2, int[] p3, int[] p4) {

        Pair a1 = new Pair(p1[0], p1[1]);
        Pair a2 = new Pair(p2[0], p2[1]);
        Pair a3 = new Pair(p3[0], p3[1]);
        Pair a4 = new Pair(p4[0], p4[1]);
        Pair p[] = new Pair[]{a1, a2, a3, a4};
        Arrays.sort(p);
        return square(p[0], p[1], p[2], p[3])
                && meas(p[0], p[1]) == meas(p[1], p[3]) && meas(p[1], p[3]) == meas(p[2], p[3]) && meas(p[2], p[3]) == meas(p[0], p[2])
                && isNotTheSamePoint(p1, p2, p3, p4);
    }

    private boolean isNotTheSamePoint(int[] p1, int[] p2, int[] p3, int[] p4) {
        return !(p1[0] == p2[0] && p1[1] == p2[1]) &&
                !(p2[0] == p3[0] && p2[1] == p3[1]) &&
                !(p3[0] == p4[0] && p3[1] == p4[1]) &&
                !(p4[0] == p1[0] && p4[1] == p1[1]);
    }

    private long meas(Pair p1, Pair p2) {
        long A = (p2.x - p1.x);
        long B = (p2.y - p1.y);
        return (A * A) + (B * B);
    }

    private int numberOfMoves(int[][][] positions, int[] a, int[] b, int[] p1, int[] p2, int[] p3, int[] p4) {
        int moves = 0;
        moves += dist(positions, 0, 0, p1, a[0], b[0]);
        moves += dist(positions, 1, 0, p2, a[1], b[1]);
        moves += dist(positions, 2, 0, p3, a[2], b[2]);
        moves += dist(positions, 3, 0, p4, a[3], b[3]);
        return moves;
    }


    private int dist(int[][][] positions, int i1, int i2, int[] dest, int a, int b) {
        int count = 0;
        int initial[] = positions[i1][i2];
        int x = initial[0];
        int y = initial[1];

        while (x != dest[0] || y != dest[1]) {
            i2++;
            x = positions[i1][i2 % 4][0];
            y = positions[i1][i2 % 4][1];
            count++;
        }
        return count;
    }

    private boolean square(Pair a, Pair b, Pair c, Pair d) {
        return orto(new Line(a, b), new Line(a, c)) &&
                orto(new Line(a, b), new Line(b, d)) &&
                orto(new Line(a, c), new Line(c, d)) &&
                orto(new Line(b, d), new Line(c, d));
    }

    private boolean orto(Line l1, Line l2) {
        return (l1.A * l2.A) + (l1.B * l2.B) == 0;
    }

    private static class Line {
        private Pair p;
        private Pair q;
        private long A;
        private long B;

        public Line(Pair a, Pair b) {
            this.p = a;
            this.q = b;
            this.A = a.y - b.y;
            this.B = b.x - a.x;
        }
    }

    private static class Pair implements Comparable<Pair> {
        private long x;
        private long y;

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

        @Override
        public String toString() {
            return "Pair{" +
                    "x=" + x +
                    ", y=" + y +
                    '}';
        }

        public int compareTo(Pair that) {
            return (int) (this.x == that.x ? this.y - that.y : this.x - that.x);
        }
    }

    Main(InputStream in, OutputStream out) {
        this.reader = new Reader(in);
        this.writer = new Writer(out);
    }

    public Main() {
        this.reader = new Reader();
        this.writer = new Writer();
    }


}

class Reader {

    private final int BUFFER_SIZE = 65536;

    private final DataInputStream din;

    private final byte[] buffer;

    private int bufferPointer, bytesRead;

    Reader() {
        din = new DataInputStream(System.in);
        buffer = new byte[BUFFER_SIZE];
        bufferPointer = bytesRead = 0;
    }

    public Reader(InputStream in) {
        din = new DataInputStream(in);
        buffer = new byte[BUFFER_SIZE];
        bufferPointer = bytesRead = 0;
    }

    public long nextUnsignedLong() throws IOException {
        long ret = 0;
        byte c = read();
        while (c <= 32) c = read();
        do {
            ret = ret * 10 + c - '0';
        } while ((c = read()) >= '0');
        return ret;
    }

    public int nextUnsignedInt() throws IOException {
        int ret = 0;
        byte c = read();
        while (c <= 32) c = read();
        do {
            ret = ret * 10 + c - '0';
        } while ((c = read()) >= '0');
        return ret;
    }

    public int nextInt() throws IOException {
        int ret = 0;
        byte c = read();
        while (c <= ' ') c = read();
        boolean neg = (c == '-');
        if (neg) {
            c = read();
        }
        do {
            ret = ret * 10 + c - '0';
        } while ((c = read()) >= '0');
        if (neg) {
            return -ret;
        }
        return ret;
    }

    public String nextString() throws IOException {
        int cnt = 0;
        char[] buf = new char[100];
        byte c;
        while ((c = read()) < 33) ;
        buf[cnt++] = (char) c;
        while ((c = read()) >= 33) {
            buf[cnt++] = (char) c;
        }
        return new String(buf, 0, cnt);
    }

    public char firstCharOfNextUnSpacedString() throws IOException {
        byte c;
        char res;
        while ((c = read()) < 33) ;
        res = (char) c;
        while ((c = read()) >= 33) ;
        return res;
    }

    private void fillBuffer() throws IOException {
        bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
        if (bytesRead == -1) {
            buffer[0] = -1;
        }
    }

    private byte read() throws IOException {
        if (bufferPointer == bytesRead) {
            fillBuffer();
        }
        return buffer[bufferPointer++];
    }
}

class Writer {
    private final BufferedWriter out;

    Writer() {
        out = new BufferedWriter(new OutputStreamWriter(System.out), 512);
    }

    public Writer(OutputStream out) {
        this.out = new BufferedWriter(new OutputStreamWriter(out), 512);
    }

    void print(char c) throws IOException {
        out.write(c);
    }

    void print(String str) throws IOException {
        out.write(str);
    }

    void println() throws IOException {
        out.write("\n");
    }

    void flush() throws IOException {
        out.flush();
    }

    @Override
    protected void finalize() throws IOException {
        out.flush();
    }
}