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.
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

import java.awt.Point;
import java.io.*;
import java.math.BigInteger;
import java.util.*;
import java.text.*;

public class cf474c {

    static BufferedReader br;
    static Scanner sc;
    static PrintWriter out;

    public static void initA() {
        try {
            br = new BufferedReader(new InputStreamReader(System.in));
            sc = new Scanner(System.in);
            out = new PrintWriter(System.out);
        } catch (Exception e) {
        }
    }

    static boolean next_permutation(Integer[] p) {
        for (int a = p.length - 2; a >= 0; --a) {
            if (p[a] < p[a + 1]) {
                for (int b = p.length - 1;; --b) {
                    if (p[b] > p[a]) {
                        int t = p[a];
                        p[a] = p[b];
                        p[b] = t;
                        for (++a, b = p.length - 1; a < b; ++a, --b) {
                            t = p[a];
                            p[a] = p[b];
                            p[b] = t;
                        }
                        return true;
                    }
                }
            }
        }
        return false;
    }

    public static String getString() {
        try {
            return br.readLine();
        } catch (Exception e) {
        }
        return "";
    }

    public static Integer getInt() {
        try {
            return Integer.parseInt(br.readLine());
        } catch (Exception e) {
        }
        return 0;
    }

    public static Integer[] getIntArr() {
        try {
            StringTokenizer temp = new StringTokenizer(br.readLine());
            int n = temp.countTokens();
            Integer temp2[] = new Integer[n];
            for (int i = 0; i < n; i++) {
                temp2[i] = Integer.parseInt(temp.nextToken());
            }
            return temp2;
        } catch (Exception e) {
        }
        return null;
    }

    public static Long[] getLongArr() {
        try {
            StringTokenizer temp = new StringTokenizer(br.readLine());
            int n = temp.countTokens();
            Long temp2[] = new Long[n];
            for (int i = 0; i < n; i++) {
                temp2[i] = Long.parseLong(temp.nextToken());
            }
            return temp2;
        } catch (Exception e) {
        }
        return null;
    }

    public static String[] getStringArr() {
        try {
            StringTokenizer temp = new StringTokenizer(br.readLine());
            int n = temp.countTokens();
            String temp2[] = new String[n];
            for (int i = 0; i < n; i++) {
                temp2[i] = (temp.nextToken());
            }
            return temp2;
        } catch (Exception e) {
        }
        return null;
    }

    public static void print(Object a) {
        out.println(a);
    }

    public static void print(String s, Object... a) {
        out.printf(s, a);
    }

    public static int nextInt() {
        return sc.nextInt();
    }

    public static double nextDouble() {
        return sc.nextDouble();
    }

    public static void main(String[] ar) {
        initA();
        cf474c c = new cf474c();
        c.solve();
        out.flush();
    }

    private static class gerombol {

        int lk;
        pair temp[] = new pair[4];

        long getHash() {
            long hash = 0;
            for (int i = 0; i < 4; i++) {
                hash *= 20011;
                hash += temp[i].skr.x;

                hash *= 20011;
                hash += temp[i].skr.y;

            }
            return hash;
        }

        boolean kotak() {
            Arrays.sort(temp);
            int le = -1;

                TreeSet<Integer> p = new TreeSet<Integer>();
            for (int i = 0; i < 4; i++) {

                for (int k = 0; k < 4; k++) {
                    if (i != k) {
                        int c = (temp[i].skr.x - temp[k].skr.x);
                        int d = (temp[i].skr.y - temp[k].skr.y);
                        c *= c;
                        d *= d;
                        p.add(c + d);
                        
                        if(c+d==0) return false;
                    }
                }
               
            }

            return p.size() == 2;
        }

        gerombol putar0() {
            gerombol re = new gerombol();
            for (int i = 0; i < 4; i++) {
                re.temp[i] = new pair(temp[i].skr.x, temp[i].skr.y, temp[i].pusat.x, temp[i].pusat.y, temp[i].putar);
                re.temp[i].skr = temp[i].skr;
                re.temp[i].pusat = temp[i].pusat;
            }
            re.temp[0] = re.temp[0].rotate();
            re.lk = lk + 1;
            return re;
        }

        gerombol putar1() {
            gerombol re = new gerombol();
            for (int i = 0; i < 4; i++) {
                re.temp[i] = new pair(temp[i].skr.x, temp[i].skr.y, temp[i].pusat.x, temp[i].pusat.y, temp[i].putar);
                re.temp[i].skr = temp[i].skr;
                re.temp[i].pusat = temp[i].pusat;
            }
            re.temp[1] = re.temp[1].rotate();
            re.lk = lk + 1;
            return re;
        }

        gerombol putar2() {
            gerombol re = new gerombol();
            for (int i = 0; i < 4; i++) {
                re.temp[i] = new pair(temp[i].skr.x, temp[i].skr.y, temp[i].pusat.x, temp[i].pusat.y, temp[i].putar);
                re.temp[i].skr = temp[i].skr;
                re.temp[i].pusat = temp[i].pusat;
            }
            re.temp[2] = re.temp[2].rotate();
            re.lk = lk + 1;
            return re;
        }

        gerombol putar3() {
            gerombol re = new gerombol();
            for (int i = 0; i < 4; i++) {
                re.temp[i] = new pair(temp[i].skr.x, temp[i].skr.y, temp[i].pusat.x, temp[i].pusat.y, temp[i].putar);
                re.temp[i].skr = temp[i].skr;
                re.temp[i].pusat = temp[i].pusat;
            }
            re.temp[3] = re.temp[3].rotate();
            re.lk = lk + 1;
            return re;
        }

        @Override
        public String toString() {
            String a = "";
            for (int i = 0; i < 4; i++) {
                a += (temp[i].skr.x + "," + temp[i].skr.y + " ");
            }
            return a + "\n";
        }
    }

    private static class pair implements Comparable<pair> {

        Point skr, pusat;
        int putar;

        pair(int a, int b, int c, int d, int p) {
            skr = new Point(a, b);
            pusat = new Point(c, d);
            putar = p;
        }

        pair rotate() {
            int geserX = -pusat.x, geserY = -pusat.y;

            int nX = skr.x + geserX, nY = skr.y + geserY;

            pair ret = new pair(-nY - geserX, nX - geserY, pusat.x, pusat.y, putar + 1);

            return ret;
        }

        @Override
        public int compareTo(pair o) {
            if (skr.x != o.skr.x) {
                return skr.x - o.skr.x;
            }
            return skr.y - o.skr.y;
        }
    }

    void solve() {
        int tc = getInt();

        while (tc-- > 0) {
            gerombol init = new gerombol();
            for (int i = 0; i < 4; i++) {
                Integer xx[] = getIntArr();
                init.temp[i] = new pair(xx[0], xx[1], xx[2], xx[3], 0);
            }
            Queue< gerombol> q = new ArrayDeque<gerombol>();
            q.add(init);

            boolean jawab = false;
            int re = 0;

            HashSet<Long> sdh = new HashSet<Long>();
            while (q.size() > 0) {
                gerombol temp = q.remove();
                if (sdh.contains(temp.getHash())) {
                    continue;
                }
                sdh.add(temp.getHash());

                if (temp.kotak()) {
                    print(temp.lk);
                  /*
                    for (int i = 0; i < 4; i++) {
                        print("%d %d -> ", temp.temp[i].skr.x, temp.temp[i].skr.y);
                        print("%d berpusat %d,%d\n", temp.temp[i].putar, temp.temp[i].pusat.x, temp.temp[i].pusat.y);
                    }
                    print("");
                    */ 
                    jawab = true;
                    break;
                }
                /*
                for (int i = 0; i < 4; i++) {
                    print("%d %d -> ", temp.temp[i].skr.x, temp.temp[i].skr.y);
                    print("%d berpusat %d,%d\n", temp.temp[i].putar, temp.temp[i].pusat.x, temp.temp[i].pusat.y);
                }
                print("");
                 * 
                 */

                re++;
                //System.out.println(re+"\n"+temp);
                if (temp.temp[0].putar < 3) {
                    q.add(temp.putar0());
                }
                if (temp.temp[1].putar < 3) {
                    q.add(temp.putar1());
                }
                if (temp.temp[2].putar < 3) {
                    q.add(temp.putar2());
                }
                if (temp.temp[3].putar < 3) {
                    q.add(temp.putar3());
                }

            }
            if (!jawab) {
                print(-1);
            }

        }
    }
}
