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.Locale;
import java.util.StringTokenizer;

public class A implements Runnable {

    private static final boolean ONLINE_JUDGE = System.getProperty("ONLINE_JUDGE") != null;

    private BufferedReader in;
    private PrintWriter out;
    private StringTokenizer tok = new StringTokenizer("");

    private void init() throws FileNotFoundException {
        Locale.setDefault(Locale.US);
        String fileName = "";
        if (ONLINE_JUDGE && fileName.isEmpty()) {
            in = new BufferedReader(new InputStreamReader(System.in));
            out = new PrintWriter(System.out);
        } else {
            if (fileName.isEmpty()) {
                in = new BufferedReader(new FileReader("input.txt"));
                out = new PrintWriter("output.txt");
            } else {
                in = new BufferedReader(new FileReader(fileName + ".in"));
                out = new PrintWriter(fileName + ".out");
            }
        }
    }

    String readString() {
        while (!tok.hasMoreTokens()) {
            try {
                tok = new StringTokenizer(in.readLine());
            } catch (Exception e) {
                return null;
            }
        }
        return tok.nextToken();
    }

    int readInt() {
        return Integer.parseInt(readString());
    }

    long readLong() {
        return Long.parseLong(readString());
    }

    double readDouble() {
        return Double.parseDouble(readString());
    }

    int[] readIntArray(int size) {
        int[] a = new int[size];
        for (int i = 0; i < size; i++) {
            a[i] = readInt();
        }
        return a;
    }

    public static void main(String[] args) {
        //new Thread(null, new _Solution(), "", 128 * (1L << 20)).start();
        new A().run();
    }

    long timeBegin, timeEnd;

    void time() {
        timeEnd = System.currentTimeMillis();
        System.err.println("Time = " + (timeEnd - timeBegin));
    }

    @Override
    public void run() {
        try {
            timeBegin = System.currentTimeMillis();
            init();
            solve();
            out.close();
            time();
        } catch (Exception e) {
            e.printStackTrace();
            System.exit(-1);
        }
    }

    long getDistSqr(int x1, int y1, int x2, int y2) {
        long dx = x1 - x2;
        long dy = y1 - y2;
        return dx * dx + dy * dy;
    }

    class Point {
        int x, y;

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

    Point[] getAllRotations(Point p, Point center) {
        p.x -= center.x;
        p.y -= center.y;
        Point[] res = new Point[]{
                new Point(p.x, p.y), // 1, 4
                new Point(-p.y, p.x), // -4, 1
                new Point(-p.x, -p.y), // -1, -4
                new Point(p.y, -p.x), // 4, -1
        };
        for (Point re : res) {
            re.x += center.x;
            re.y += center.y;
        }
        p.x += center.x;
        p.y += center.y;
        return res;
    }

    boolean isSquare(Point[] points) {
        for (int i = 0; i < 4; i++) {
            for (int j = i + 1; j < 4; j++) {
                if (points[i].x == points[j].x && points[i].y == points[j].y) {
                    return false;
                }
            }
        }
        for (int i = 0; i < 4; i++) {
            points[i].x *= 2;
            points[i].y *= 2;
        }
        boolean result = false;
        for (int j = 1; j < 4; j++) {
            int centerX = (points[0].x + points[j].x) / 2;
            int centerY = (points[0].y + points[j].y) / 2;
            Point[] rotations = getAllRotations(points[0], new Point(centerX, centerY));
            int count = 0;
            for (int i = 0; i < 4; i++) {
                for (int k = 0; k < 4; k++) {
                    if (points[i].x == rotations[k].x && points[i].y == rotations[k].y) {
                        count++;
                    }
                }
            }
            result |= count == 4 ;
        }

        for (int i = 0; i < 4; i++) {
            points[i].x /= 2;
            points[i].y /= 2;
        }
        return result;
    }

    private void solve() throws IOException {
        int n = readInt();
        for (int i = 0; i < n; i++) {
            Point[] humster = new Point[4], house = new Point[4];
            for (int j = 0; j < 4; j++) {
                humster[j] = new Point(readInt(), readInt());
                house[j] = new Point(readInt(), readInt());
            }
            int ans = Integer.MAX_VALUE;
            Point[] p1 = getAllRotations(humster[0], house[0]);
            Point[] p2 = getAllRotations(humster[1], house[1]);
            Point[] p3 = getAllRotations(humster[2], house[2]);
            Point[] p4 = getAllRotations(humster[3], house[3]);
            for (int step1 = 0; step1 < 4; step1++) {
                for (int step2 = 0; step2 < 4; step2++) {
                    for (int step3 = 0; step3 < 4; step3++) {
                        for (int step4 = 0; step4 < 4; step4++) {
                            if (isSquare(new Point[] {
                                    p1[step1],
                                    p2[step2],
                                    p3[step3],
                                    p4[step4]
                            })) {
                                ans = Math.min(ans, step1 + step2 + step3 + step4);
                            }
                        }
                    }
                }
            }
            if (ans == Integer.MAX_VALUE) {
                out.println(-1);
            } else {
                out.println(ans);
            }
        }
    }
}