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

public class Main implements Runnable {

    public final String TASKNAME = "";
    public final boolean CONSOLE = true;

    public static void main(String[] args) {
        new Thread(new Main()).start();
    }

    BufferedReader br;
    PrintWriter out;
    StringTokenizer in;

    public String nextToken() throws IOException {
        while (in == null || !in.hasMoreTokens()) {
            in = new StringTokenizer(br.readLine());
        }
        return in.nextToken();
    }

    public String nextLine() throws IOException {
        return br.readLine();
    }


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

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

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

    private void solve() throws IOException {
        int n = nextInt();
        for (int i = 0; i < n; i++) {
            int[][] position = new int[4][2];
            int[][] home = new int[4][2];

            for (int j = 0; j < 4; j++) {
                position[j][0] = nextInt();
                position[j][1] = nextInt();
                home[j][0] = nextInt();
                home[j][1] = nextInt();
            }

            int res = 555555;

//            if (isSquare(position[0][0], position[0][1], position[1][0], position[1][1], position[2][0], position[2][1], position[3][0], position[3][1])) {
//                res = 0;
//            } else {
            for (int i1 = 0; i1 < 4; ++i1) {
                for (int i2 = 0; i2 < 4; ++i2) {
                    for (int i3 = 0; i3 < 4; ++i3) {
                        for (int i4 = 0; i4 < 4; ++i4) {
                            if (isSquare(position[0][0], position[0][1], position[1][0], position[1][1], position[2][0], position[2][1], position[3][0], position[3][1])) {
                                if (res > i1 + i2 + i3 + i4) {
                                    res = i1 + i2 + i3 + i4;
                                }
                            }
                            position[3] = rotate(position[3][0], position[3][1], home[3][0], home[3][1]);
                        }
                        position[2] = rotate(position[2][0], position[2][1], home[2][0], home[2][1]);
                    }
                    position[1] = rotate(position[1][0], position[1][1], home[1][0], home[1][1]);
                }
                position[0] = rotate(position[0][0], position[0][1], home[0][0], home[0][1]);
            }
//            }

            if (res == 555555)
                out.println(-1);
            else
                out.println(res);
        }
    }

//    private int[] rotate(int x, int y, int a, int b) {
//        if (x == a || y == b) {
//            if (x == a && y == b) {
//
//            } else if (x == a) {
//                if (y < b) {
//                    x = a + (b - y);
//                } else {
//                    x = a - (y - b);
//                }
//                y = b;
//            } else {
//                if (x > a) {
//                    y = b + (x - a);
//                } else {
//                    y = b - (a - x);
//                }
//                x = a;
//            }
//
//        } else {
//            if (x > a && y > b) {
//                x = a - (x - a);
//            } else if (x < a && y > b) {
//                y = b - (y - b);
//            } else if (x < a && y < b) {
//                x = a + (a - x);
//            } else {
//                y = b + (b - y);
//            }
//        }
//        return new int[]{x, y};
//    }

    private int[] rotate(int x, int y, int a, int b) {
        return new int[]{b - y + a, x - a + b};
    }

    private boolean isSquare(int x1, int y1, int x2, int y2, int x3, int y3, int x4, int y4) {
        long L12 = (long) (Math.pow(x1 - x2, 2) + Math.pow(y1 - y2, 2));
        long L13 = (long) (Math.pow(x1 - x3, 2) + Math.pow(y1 - y3, 2));
        long L14 = (long) (Math.pow(x1 - x4, 2) + Math.pow(y1 - y4, 2));
        long L23 = (long) (Math.pow(x3 - x2, 2) + Math.pow(y3 - y2, 2));
        long L24 = (long) (Math.pow(x4 - x2, 2) + Math.pow(y4 - y2, 2));
        long L34 = (long) (Math.pow(x3 - x4, 2) + Math.pow(y3 - y4, 2));

        long[] mass = {L12, L13, L14, L23, L24, L34};
        Arrays.sort(mass);

        for (int i = 0; i <= 3; i++) {
            if (mass[0] != mass[i] || mass[i] == 0)
                return false;
        }

        if (mass[4] != mass[5] || mass[4] == 0 || mass[5] == 0)
            return false;

//        if (Math.sqrt(Math.pow(x1 - x2, 2) + Math.pow(y1 - y2, 2)) == Math.sqrt(Math.pow(x3 - x4, 2) + Math.pow(y3 - y4, 2))) {
//            if (Math.sqrt(Math.pow(x1 - x3, 2) + Math.pow(y1 - y3, 2)) == Math.sqrt(Math.pow(x2 - x4, 2) + Math.pow(y2 - y4, 2))) {
//                if (Math.sqrt(Math.pow(x1 - x4, 2) + Math.pow(y1 - y4, 2)) == Math.sqrt(Math.pow(x2 - x3, 2) + Math.pow(y2 - y3, 2)))
//                    return true;
//            }
//        }
        return true;
    }

    public void run() {
        try {
            if (CONSOLE) {
                br = new BufferedReader(new InputStreamReader(System.in));
                out = new PrintWriter(System.out);
            } else {
                br = new BufferedReader(new FileReader(new File(TASKNAME + ".in")));
                out = new PrintWriter(new File(TASKNAME + ".out"));
            }

            solve();

            out.flush();
            out.close();
        } catch (IOException e) {
            e.printStackTrace();
            System.exit(1);
        }

    }
}