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.
//44,45,47
import java.util.*;
import java.lang.*;
import java.io.*;
import java.awt.*;
public class CF474C
{    //*****************************************    VARIABLE DECLERATION SECTION   ********************************************************************;
        double x;double y;
         CF474C(double x,double y)
        {
           this.x=x;this.y=y;  
        }
    //*****************************************    VARIABLE DECLERATION ENDS   ********************************************************************;

    //************************************************   MAIN FUNCTION  *************************************************************************; 
    public static void main(String[] args) 
    {   
          FastReader scan=new FastReader();
          int n=scan.nextInt();
          while(n--!=0)
          {
              CF474C[][] arr=new CF474C[4][4];
                 double x=scan.nextDouble(),y=scan.nextDouble(),px=scan.nextDouble(),py=scan.nextDouble();
                arr[0][0]=new CF474C(x,y);
                double a,b;
                a=2*px-x;b=2*py-y;
                arr[0][2]=new CF474C(a,b);
                arr[0][1]=new CF474C(px-(y-py),py+(x-px));
                arr[0][3]=new CF474C(2*px-arr[0][1].x,2*py-arr[0][1].y);

                x=scan.nextDouble();y=scan.nextDouble();px=scan.nextDouble();py=scan.nextDouble();
                arr[1][0]=new CF474C(x,y);
                a=2*px-x;b=2*py-y;
                arr[1][2]=new CF474C(a,b);
                arr[1][1]=new CF474C(px-(y-py),py+(x-px));
                arr[1][3]=new CF474C(2*px-arr[1][1].x,2*py-arr[1][1].y);
                //System.out.println(arr[0][1].y);

                x=scan.nextDouble();y=scan.nextDouble();px=scan.nextDouble();py=scan.nextDouble();
                 arr[2][0]=new CF474C(x,y);
                a=2*px-x;b=2*py-y;
                arr[2][2]=new CF474C(a,b);
                arr[2][1]=new CF474C(px-(y-py),py+(x-px));
                arr[2][3]=new CF474C(2*px-arr[2][1].x,2*py-arr[2][1].y);

                x=scan.nextDouble();y=scan.nextDouble();px=scan.nextDouble();py=scan.nextDouble();
                arr[3][0]=new CF474C(x,y);
                a=2*px-x;b=2*py-y;
                arr[3][2]=new CF474C(a,b);
                arr[3][1]=new CF474C(px-(y-py),py+(x-px));
                arr[3][3]=new CF474C(2*px-arr[3][1].x,2*py-arr[3][1].y);
                /*for(int i=0;i<4;i++)
                {
                    for(int j=0;j<4;j++)
                        System.out.print(arr[i][j].x+"****"+arr[i][j].y+"       ");
                    System.out.println("");
                }*/

                boolean flag=false;
                int cnt=1000;
                int[] dup=new int[4];
                dup[3]=-1;
                int i=3;
                while(i>=0)
                {
                    if(dup[i]==3)
                    {
                        if(i==0)break;
                        else
                        {
                          for(int j=i;j<4;j++)dup[j]=0;
                          i--;  
                          continue;
                        }
                    }
                    else
                    {
                        dup[i]++;
                        for(int j=i+1;j<4;j++)dup[j]=0;
                        i=3;
                    }
                    //System.out.println(dup[0]+" "+dup[1]+" "+dup[2]+" "+dup[3]);
                    int tmp=dup[0]+dup[1]+dup[2]+dup[3];
                    double x0=arr[0][dup[0]].x;
                    double y0=arr[0][dup[0]].y;

                    double x1=arr[1][dup[1]].x;
                    double y1=arr[1][dup[1]].y;

                    double x2=arr[2][dup[2]].x;
                    double y2=arr[2][dup[2]].y;

                    double x3=arr[3][dup[3]].x;
                    double y3=arr[3][dup[3]].y;

                    if(square(x0,y0,x1,y1,x2,y2,x3,y3)==true)
                    {   flag=true;
                        if(tmp<cnt)cnt=tmp;
                    }
                }
                if(flag)System.out.println(cnt);
                   else System.out.println(-1);
          }



    }
    //***********************************************  MAIN FUNCTION ENDS   *********************************************************************;

    //**********************************************   AUXILIARY FUNCTIONS  **********************************************************************;
    static boolean square(double x0,double y0,double x1,double y1,double x2,double y2,double x3,double y3)
    {  TreeSet<Double> ts=new TreeSet<Double>();

        boolean flag2=true;
        if((x0==x1&&y0==y1)||(x0==x2&&y0==y2)||(x0==x3&&y0==y3)||(x1==x2&&y1==y2)||(x1==x3&&y1==y3)||(x2==x3&&y2==y3))flag2=false;

        double d=Math.sqrt((x1-x0)*(x1-x0)+(y1-y0)*(y1-y0));
        ts.add(d);

        d=Math.sqrt((x2-x0)*(x2-x0)+(y2-y0)*(y2-y0));
        ts.add(d);
        d=Math.sqrt((x3-x0)*(x3-x0)+(y3-y0)*(y3-y0));
        ts.add(d);
        d=Math.sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1));
        ts.add(d);
        d=Math.sqrt((x3-x1)*(x3-x1)+(y3-y1)*(y3-y1));
        ts.add(d);
        d=Math.sqrt((x3-x2)*(x3-x2)+(y3-y2)*(y3-y2));
        ts.add(d);
        if(ts.size()==2&&flag2)
        {

          //System.out.println(x0+" "+y0+" "+x1+" "+y1+" "+x2+" "+y2+" "+x3+" "+y3+" ");
          return true;  
        }
        return false;



    }
    //**********************************************   AUXILIARY FUNCTIONS  ENDS  **********************************************************************;

    //**********************************************   INPUT FUNCTIONS     ******************************************************************************;
    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;
        }
    }
    //**********************************************   INPUT FUNCTIONS     ******************************************************************************;
}