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.math.BigInteger;
import java.util.*;

 public class Main {
     static long arr[], N, K, x1, x2, y1, y2;
     static BigInteger dp[][];
     static boolean reach[][];
     static String str1[];
     static String str2[];
     static List<int[]>[] adj;
     static int mod = (int) (1e9 + 9);

     public static void main(String[] args) throws IOException {
         Scanner input = new Scanner(System.in);
         int n = input.nextInt();
         for(int t=0 ; t<n ; t++){
            List<List<Point>> list = new ArrayList<>();
            for(int j=0 ; j<4 ; j++)
                list.add(new ArrayList<>());
            Point [] retationPoints  = new Point[4];
            for(int j=0 ; j<4 ; j++){
                list.get(j).add(new Point(input.nextInt(),input.nextInt()));
                retationPoints[j] = new Point(input.nextInt(),input.nextInt());
                Point p = list.get(j).get(0);
                for(int k=0 ; k<3 ; k++){
                    list.get(j).add(p = rotate(p,retationPoints[j]));
                }
            }
            boolean done =  false;
            int ans = Integer.MAX_VALUE;
            for(int i =0 ; i< 4 ; i++){
                for(int j=0 ; j<4 ; j++){
                    for(int k=0 ; k<4 ; k++){
                        for(int s = 0 ; s<4 ; s++){
                            if(isSquare(list.get(0).get(i),list.get(1).get(j),list.get(2).get(k),list.get(3).get(s))){
                                done = true;
                                ans = Math.min(ans,i+j+k+s);
                            }
                        }
                    }
                }
            }
             if(!done)
                 System.out.println(-1);
             else System.out.println(ans);
         }
     }
     // tree diameter

     static class Point
     {
         int x, y;

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

     };



     static Point rotate (Point p1 , Point p2){
         Point p3 = new Point(-1,-1);
         p3.x = p2.y - p1.y + p2.x;
         p3.y = p1.x - p2.x + p2.y;
         return p3;
     }

     // A utility function to find square of distance
// from point 'p' to point 'q'
     static int distSq(Point p, Point q)
     {
         return (p.x - q.x) * (p.x - q.x) + (p.y - q.y) * (p.y - q.y);
     }

     // This function returns true if (p1, p2, p3, p4) form a
// square, otherwise false
     static boolean isSquare(Point p1, Point p2, Point p3, Point p4)
     {
         int d2 = distSq(p1, p2); // from p1 to p2
         int d3 = distSq(p1, p3); // from p1 to p3
         int d4 = distSq(p1, p4); // from p1 to p4

         if (d2 == 0 || d3 == 0 || d4 == 0)
             return false;

         // If lengths if (p1, p2) and (p1, p3) are same, then
         // following conditions must met to form a square.
         // 1) Square of length of (p1, p4) is same as twice
         // the square of (p1, p2)
         // 2) Square of length of (p2, p3) is same
         // as twice the square of (p2, p4)

         if (d2 == d3 && 2 * d2 == d4
                 && 2 * distSq(p2, p4) == distSq(p2, p3))
         {
             return true;
         }

         // The below two cases are similar to above case
         if (d3 == d4 && 2 * d3 == d2
                 && 2 * distSq(p3, p2) == distSq(p3, p4))
         {
             return true;
         }
         if (d2 == d4 && 2 * d2 == d3
                 && 2 * distSq(p2, p3) == distSq(p2, p4))
         {
             return true;
         }

         return false;
     }

     static class Scanner {
         StringTokenizer st;
         BufferedReader br;

         public Scanner(InputStream s) {
             br = new BufferedReader(new InputStreamReader(s));
         }

         public Scanner(String s) throws FileNotFoundException {
             br = new BufferedReader(new FileReader(s));
         }

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

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

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

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

         public boolean ready() throws IOException {
             return br.ready();
         }

         public double nextDouble() throws IOException {
             String x = next();
             StringBuilder sb = new StringBuilder("0");
             double res = 0, f = 1;
             boolean dec = false, neg = false;
             int start = 0;
             if (x.charAt(0) == '-') {
                 neg = true;
                 start++;
             }
             for (int i = start; i < x.length(); i++)
                 if (x.charAt(i) == '.') {
                     res = Integer.parseInt(sb.toString());
                     sb = new StringBuilder("0");
                     dec = true;
                 } else {
                     sb.append(x.charAt(i));
                     if (dec)
                         f *= 10;
                 }
             res += Integer.parseInt(sb.toString()) / f;
             return res * (neg ? -1 : 1);
         }
     }
 }



