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.BufferedWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Objects;
import java.util.StringTokenizer;

public class P474C {

    static boolean multipleIndependent = true;

    void run() {
        Integer[][] r1 = rotations(in.nextIntArray(2), in.nextIntArray(2));
        Integer[][] r2 = rotations(in.nextIntArray(2), in.nextIntArray(2));
        Integer[][] r3 = rotations(in.nextIntArray(2), in.nextIntArray(2));
        Integer[][] r4 = rotations(in.nextIntArray(2), in.nextIntArray(2));
        int i = 0;
        int min = Integer.MAX_VALUE;
        for (Integer[] p1 : r1) {
            int j = 0;
            for (Integer[] p2 : r2) {
                int k = 0;
                for (Integer[] p3 : r3) {
                    int l = 0;
                    for (Integer[] p4 : r4) {
                        if (isSquare(new Integer[][]{p1, p2, p3, p4})) {
                            min = Math.min(min, i + j + k + l);
                        }
                        l++;
                    }
                    k++;
                }
                j++;
            }
            i++;
        }
        out.println(min == Integer.MAX_VALUE ? "-1" : min);
    }

    boolean isSquare(Integer[][] points) {
        Arrays.sort(points,
                Comparator.comparing((Integer[] a) -> a[0])
                        .thenComparing(a -> a[1])
        );
        int dx = points[1][0] - points[0][0];
        int dy = points[1][1] - points[0][1];
        if (dx == 0 && dy == 0) {
            return false;
        }
        Integer[][] square1 = new Integer[][]{
            {points[1][0] - dy, points[1][1] + dx},
            {points[0][0] - dy, points[0][1] + dx}
        };
        Integer[][] square2 = new Integer[][]{
            {points[1][0] + dy, points[1][1] - dx},
            {points[0][0] + dy, points[0][1] - dx}
        };
        return isEqual(square1[0], points[2]) && isEqual(square1[1], points[3])
                || isEqual(square1[0], points[3]) && isEqual(square1[1], points[2])
                || isEqual(square2[0], points[2]) && isEqual(square2[1], points[3])
                || isEqual(square2[0], points[3]) && isEqual(square2[1], points[2]);
    }

    boolean isEqual(Integer[] p1, Integer[] p2) {
        return Objects.equals(p1[0], p2[0]) && Objects.equals(p1[1], p2[1]);
    }

    Integer[][] rotations(int[] p, int[] c) {
        int dx = p[0] - c[0];
        int dy = p[1] - c[1];
        return new Integer[][]{
            {c[0] + dx, c[1] + dy},
            {c[0] - dy, c[1] + dx},
            {c[0] - dx, c[1] - dy},
            {c[0] + dy, c[1] - dx}
        };
    }

    /* -----: Template :----- */
    static InputReader in;
    static PrintWriter out;

    public static void main(String[] args) {
        try (PrintWriter o = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)))) {
            in = new InputReader(System.in);
            out = o;
            int q = multipleIndependent ? in.nextInt() : 1;
            while (q-- > 0) {
                new P474C().run();
            }
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }

    static Integer[] toWrapper(int[] arr) {
        Integer[] res = new Integer[arr.length];
        for (int i = 0; i < arr.length; i++) {
            res[i] = arr[i];
        }
        return res;
    }

    static Integer[][] toWrapper(int[][] arr) {
        Integer[][] res = new Integer[arr.length][];
        for (int i = 0; i < arr.length; i++) {
            res[i] = toWrapper(arr[i]);
        }
        return res;
    }

    static Long[] toWrapper(long[] arr) {
        Long[] res = new Long[arr.length];
        for (int i = 0; i < arr.length; i++) {
            res[i] = arr[i];
        }
        return res;
    }

    static Long[][] toWrapper(long[][] arr) {
        Long[][] res = new Long[arr.length][];
        for (int i = 0; i < arr.length; i++) {
            res[i] = toWrapper(arr[i]);
        }
        return res;
    }

    static class InputReader {

        private final BufferedReader reader;
        private StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            int bufferSize = 32 * 1024;
            reader = new BufferedReader(new InputStreamReader(stream), bufferSize);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public String nextLine() {
            if (true) {
                throw new RuntimeException("nextLine: not tested");
            }
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            StringBuilder sb = new StringBuilder();
            return tokenizer.nextToken("\n");
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

        public int[] nextIntArray(int n) {
            int[] arr = new int[n];
            for (int i = 0; i < n; i++) {
                arr[i] = nextInt();
            }
            return arr;
        }

        public long[] nextLongArray(int n) {
            long[] arr = new long[n];
            for (int i = 0; i < n; i++) {
                arr[i] = nextLong();
            }
            return arr;
        }

        public int[][] nextIntMap(int n, int m) {
            int[][] map = new int[n][m];
            for (int i = 0; i < n; i++) {
                map[i] = nextIntArray(m);
            }
            return map;
        }

        public long[][] nextLongMap(int n, int m) {
            long[][] map = new long[n][m];
            for (int i = 0; i < n; i++) {
                map[i] = nextLongArray(m);
            }
            return map;
        }

        public char[][] nextCharMap(int n) {
            char[][] map = new char[n][];
            for (int i = 0; i < n; i++) {
                map[i] = next().toCharArray();
            }
            return map;
        }
    }
}