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.IOException;
import java.util.InputMismatchException;

/**
 * Created by jizhe on 2016/2/5.
 */
public class CaptainMarmot {
    public static class FasterScanner {
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;

        public int read() {
            if (numChars == -1)
                throw new InputMismatchException();
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = System.in.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0)
                    return -1;
            }
            return buf[curChar++];
        }

        public String nextLine() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            StringBuilder res = new StringBuilder();
            do {
                res.appendCodePoint(c);
                c = read();
            } while (!isEndOfLine(c));
            return res.toString();
        }

        public String nextString() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            StringBuilder res = new StringBuilder();
            do {
                res.appendCodePoint(c);
                c = read();
            } while (!isSpaceChar(c));
            return res.toString();
        }

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

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

        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;
        }

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

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

    private static class Point
    {
        int x, y;

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

    private static Point rotate(Point current, Point home, int times)
    {
        int relX = current.x-home.x;
        int relY = current.y-home.y;

        if( times == 1 )
        {
            return new Point(-relY+home.x, relX+home.y);
        }
        else if( times == 2 )
        {
            return new Point(-relX+home.x, -relY+home.y);
        }
        else
        {
            return new Point(relY+home.x, -relX+home.y);
        }
    }

    private static boolean isSquare(Point[] points)
    {
        long a = distance(points[0], points[1]);
        long b = distance(points[0], points[2]);

        int A = 0, B, C, D;
        if( a < b )
        {
            C = 2;
            B = 1;
            D = 3;
        }
        else if( a > b )
        {
            C = 1;
            B = 2;
            D = 3;
        }
        else
        {
            C = 3;
            B = 1;
            D = 2;
        }

        //System.out.printf("A: %d, B: %d, C: %d, D: %d\n", A, B, C, D);

        long distanceAC = distance(points[A], points[C]);
        long distanceBD = distance(points[B], points[D]);
        if( distanceAC != distanceBD || distanceAC == 0 || distanceBD == 0 )
        {
            return false;
        }

        long distanceAB = distance(points[A], points[B]);
        if( distanceAC != 2*distanceAB || distanceAB == 0 )
        {
            return false;
        }

        long distanceBC = distance(points[B], points[C]);
        if( distanceAC != 2*distanceBC || distanceBC == 0 )
        {
            return false;
        }

        long distanceCD = distance(points[C], points[D]);
        if( distanceAC != 2*distanceCD || distanceCD == 0 )
        {
            return false;
        }

        long distanceDA = distance(points[D], points[A]);
        if( distanceAC != 2*distanceDA || distanceDA == 0 )
        {
            return false;
        }

        return true;
    }

    private static long distance(Point p1, Point p2)
    {
        return (long)(p1.x-p2.x)*(p1.x-p2.x)+(long)(p1.y-p2.y)*(p1.y-p2.y);
    }

    public static void main(String[] args) {
        //Scanner in = new Scanner(new BufferedInputStream(System.in));
        FasterScanner in = new FasterScanner();
        StringBuilder out = new StringBuilder();

        int N = in.nextInt();
        //Point[] points = new Point[4];
        Point[] homes = new Point[4];
        Point[][] rotatePoints = new Point[4][4];
        Point[] points = new Point[4];
        for( int i = 0; i < N; i++ )
        {
            for( int j = 0; j < 4; j++ )
            {
                rotatePoints[j][0] = new Point(in.nextInt(), in.nextInt());
                homes[j] = new Point(in.nextInt(), in.nextInt());
            }

            for( int j = 0; j < 4; j++ )
            {
                for( int k = 1; k < 4; k++ )
                {
                    rotatePoints[j][k] = rotate(rotatePoints[j][0], homes[j], k);
                    //System.out.printf("rotatePoints[%d][%d]: (%d, %d)\n", j, k, rotatePoints[j][k].x, rotatePoints[j][k].y);
                }
            }

            int[] rotateTimes = new int[4];

            /*rotateTimes[2] = 1;
            for( int k = 0; k < 4; k++ )
            {
                points[k] = rotatePoints[k][rotateTimes[k]];
                System.out.printf("(%d, %d)\n", points[k].x, points[k].y);
            }

            if( isSquare(points) )
            {
                System.out.printf("Form square, rotateTimes: %d %d %d %d\n", rotateTimes[0], rotateTimes[1], rotateTimes[2], rotateTimes[3]);
                int sum = rotateTimes[0]+rotateTimes[1]+rotateTimes[2]+rotateTimes[3];
            }*/

            int min = Integer.MAX_VALUE;
            while( true )
            {
                for( int k = 0; k < 4; k++ )
                {
                    points[k] = rotatePoints[k][rotateTimes[k]];
                }

                if( isSquare(points) )
                {
                    //System.out.printf("Form square, rotateTimes: %d %d %d %d\n", rotateTimes[0], rotateTimes[1], rotateTimes[2], rotateTimes[3]);
                    int sum = rotateTimes[0]+rotateTimes[1]+rotateTimes[2]+rotateTimes[3];
                    if( sum < min )
                    {
                        min = sum;
                    }
                }

                int j;
                for( j = 3; j > -1; j-- )
                {
                    rotateTimes[j]++;
                    if( rotateTimes[j] == 4 )
                    {
                        rotateTimes[j] = 0;
                    }
                    else
                    {
                        break;
                    }
                }

                /*System.out.printf("rotateTimes:\n");
                for( int k = 0; k < 4; k++ )
                {
                    System.out.printf("%d ", rotateTimes[k]);
                }
                System.out.printf("\n");*/

                if( j == -1 )
                {
                    break;
                }
            }

            if( min == Integer.MAX_VALUE )
            {
                out.append("-1\n");
            }
            else
            {
                out.append(min+"\n");
            }
        }

        System.out.printf("%s\n", out.toString());
    }
}
