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.Iterator;
import java.util.Collection;
import java.util.InputMismatchException;
import java.io.IOException;
import java.util.Deque;
import java.util.ArrayList;
import java.util.List;
import java.util.ArrayDeque;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Pradyumn Agrawal coderbond007  PLEASE!! PLEASE!! HACK MY SOLUTION!!
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastReader in = new FastReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskC solver = new TaskC();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskC {
        public void solve(int testNumber, FastReader in, PrintWriter out) {
            int N = in.nextInt();
            for (int n = 1; n <= N; ++n) {
                int[][] co = in.nextIntMap(4, 4);
                int min = 999;
                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 (isSquare(co)) {
                                    min = Math.min(min, a + b + c + d);
                                }
                                rotate(co[3]);
                            }
                            rotate(co[2]);
                        }
                        rotate(co[1]);
                    }
                    rotate(co[0]);
                }
                out.println(min == 999 ? -1 : min);
            }
        }

        private boolean isSquare(int[][] co) {
            Permutation permutation = new Permutation(4);
            for (List<Integer> list : permutation) {
                if (list == null) break;
                int i1 = list.get(0);
                int i2 = list.get(1);
                int i3 = list.get(2);
                int i4 = list.get(3);
                if (isSquare(co[i1][0], co[i1][1], co[i2][0], co[i2][1], co[i3][0], co[i3][1], co[i4][0], co[i4][1])) {
                    return true;
                }
            }
            return false;
        }

        private static boolean isSquare(int ax, int ay, int bx, int by, int cx, int cy, int dx, int dy) {
            int vx = bx - ax;
            int vy = by - ay;
            return (!(dx == ax && dy == ay) && cx == ax + vy && cy == ay - vx && dx == bx + vy && dy == by - vx);
        }

        private void rotate(int[] co) {
            int x = co[0], y = co[1];
            int a = co[2], b = co[3];
            int nx = -(y - b) + a;
            int ny = (x - a) + b;
            co[0] = nx;
            co[1] = ny;
        }

    }

    static class FastReader {
        private InputStream stream;
        private byte[] buf = new byte[8192];
        private int curChar;
        private int pnumChars;
        private FastReader.SpaceCharFilter filter;

        public FastReader(InputStream stream) {
            this.stream = stream;
        }

        private int pread() {
            if (pnumChars == -1) {
                throw new InputMismatchException();
            }
            if (curChar >= pnumChars) {
                curChar = 0;
                try {
                    pnumChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (pnumChars <= 0) {
                    return -1;
                }
            }
            return buf[curChar++];
        }

        public int nextInt() {
            int c = pread();
            while (isSpaceChar(c))
                c = pread();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = pread();
            }
            int res = 0;
            do {
                if (c == ',') {
                    c = pread();
                }
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = pread();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

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

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

        private boolean isSpaceChar(int c) {
            if (filter != null) {
                return filter.isSpaceChar(c);
            }
            return isWhitespace(c);
        }

        private static boolean isWhitespace(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        private interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }

    static class Permutation implements Iterable<List<Integer>> {
        int n;
        boolean[] used;
        List<Integer> perm;
        Deque<Integer> ist;
        Permutation.PermutationIterator it;

        public Permutation(int n) {
            this.n = n;
            used = new boolean[n];
            perm = new ArrayList<>();
            ist = new ArrayDeque<>();
            ist.add(-1);
            it = new Permutation.PermutationIterator(this);
        }

        List<Integer> next() {
            out:
            while (!ist.isEmpty()) {
                int k = ist.pop();

                if (k != -1) {
                    // Return in the middle of loop
                    used[k] = false;
                    perm.remove(perm.size() - 1);
                } else {
                    // From the beginning
                    int pos = perm.size();

                    if (pos == n) {
                        // perm Operation on =========================
                        return perm;
                        // perm Operation on =========================
                    }
                }
                for (int i = k + 1; i < n; i++) {
                    if (!used[i]) {
                        ist.push(i);

                        used[i] = true;
                        perm.add(i);
                        ist.push(-1);
                        continue out;
                    }
                }
            }
            return null;
        }


        public Iterator<List<Integer>> iterator() {
            return it;
        }

        static class PermutationIterator implements Iterator<List<Integer>> {
            Permutation p;

            PermutationIterator(Permutation p) {
                this.p = p;
            }


            public boolean hasNext() {
                return !p.ist.isEmpty();
            }


            public List<Integer> next() {
                return p.next();
            }

        }

    }
}

