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.
//package com.company;

import java.util.*;
import java.io.*;
import static java.lang.Math.*;
import java.awt.Point;

public class PracticeProblem
{
    /*
     * This FastReader code is taken from GeeksForGeeks.com
     * https://www.geeksforgeeks.org/fast-io-in-java-in-competitive-programming/
     *
     * The article was written by Rishabh Mahrsee
     */
    public static class FastReader
    {
        BufferedReader br;
        StringTokenizer st;

        public FastReader()
        {
            br = new BufferedReader(new
                    InputStreamReader(System.in));
        }

        String next()
        {
            while (st == null || !st.hasMoreElements())
            {
                try
                {
                    st = new StringTokenizer(br.readLine());
                }
                catch (IOException  e)
                {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

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

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

        double nextDouble()
        {
            return Double.parseDouble(next());
        }

        String nextLine()
        {
            String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
        }
    }

    public static FastReader file = new FastReader();
    public static PrintWriter out = new PrintWriter(System.out);
    public static final int MOD = (int)1e9 + 7;

    public static void main(String[] args)
    {
        int n = file.nextInt();

        for (int i = 0; i < n; i++)
            solve();

        out.close();
    }

    private static void solve()
    {
        Point p1 = new Point(file.nextInt(), file.nextInt()), h1 = new Point(file.nextInt(), file.nextInt());
        Point p2 = new Point(file.nextInt(), file.nextInt()), h2 = new Point(file.nextInt(), file.nextInt());
        Point p3 = new Point(file.nextInt(), file.nextInt()), h3 = new Point(file.nextInt(), file.nextInt());
        Point p4 = new Point(file.nextInt(), file.nextInt()), h4 = new Point(file.nextInt(), file.nextInt());

        Point[] points1 = new Point[4];
        Point[] points2 = new Point[4];
        Point[] points3 = new Point[4];
        Point[] points4 = new Point[4];

        points1[0] = p1;
        points2[0] = p2;
        points3[0] = p3;
        points4[0] = p4;

        for (int i = 1; i <= 3; i++)
        {
            points1[i] = new Point(h1.x + -(points1[i - 1].y-h1.y), h1.y + (points1[i - 1].x-h1.x));
            points2[i] = new Point(h2.x + -(points2[i - 1].y-h2.y), h2.y + (points2[i - 1].x-h2.x));
            points3[i] = new Point(h3.x + -(points3[i - 1].y-h3.y), h3.y + (points3[i - 1].x-h3.x));
            points4[i] = new Point(h4.x + -(points4[i - 1].y-h4.y), h4.y + (points4[i - 1].x-h4.x));
        }
        int minCost = -1;
        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(points1[a], points2[b], points3[c], points4[d]))
                        {
                            if (minCost == -1 || a + b + c + d < minCost)
                            {
                                minCost = a + b + c + d;
                            }
                        }
                    }
                }
            }
        }

        out.println(minCost);

    }

    /**
     * Finds whether or not the points are arranged in a square according to the definition of a square
     * @param point1
     * @param point2
     * @param point3
     * @param point4
     * @return true if the points are arranged in a square, false otherwise
     */
    private static boolean isSquare(Point point1, Point point2, Point point3, Point point4)
    {
        if (point1.equals(point2) && point2.equals(point3) && point3.equals(point4))
        {
            return false;
        }
        double dist1 = dist(point1, point2);
        double dist2 = dist(point1, point3);
        double dist3 = dist(point1, point4);

        Point diagonal = null;
        Point adj1 = null;
        Point adj2 = null;
        if (dist1 == dist2 && dist1 != 0 && dist3 != 0)
        {
            diagonal = point4;
            adj1 = point2;
            adj2 = point3;
        }
        else if (dist1 == dist3 && dist1 != 0 && dist2 != 0)
        {
            diagonal = point3;
            adj1 = point2;
            adj2 = point4;
        }
        else if (dist2 == dist3 && dist2 != 0 && dist1 != 0)
        {
            diagonal = point2;
            adj1 = point3;
            adj2 = point4;
        }

        if (diagonal == null)
        {
            return false;
        }

        if (!(dist(adj1, diagonal) == dist(adj2, diagonal) && dist(adj1, diagonal) == dist(point1, adj1)))
        {
            return false;
        }
        // At this point, we know we have a rhombus, now we have to check that the diagonals are the same
        if (dist(point1, diagonal) == dist(adj1, adj2))
        {
            return true;
        }

        return false;
    }

    private static double dist(Point a, Point b)
    {
        return sqrt(((long)b.x - a.x)*((long)b.x - a.x) + ((long)b.y - a.y)*((long)b.y - a.y));
    }


}