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.OutputStream;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskC solver = new TaskC();
		solver.solve(1, in, out);
		out.close();
	}
}

class TaskC {
    private static final int INF = Integer.MAX_VALUE >> 1;

    public void solve(int testNumber, InputReader jin, PrintWriter jout) {
        int n = jin.int32();
        for(int tc = 0; tc < n; tc++) {
            _solve(jin, jout);
        }
    }

    private void _solve(InputReader jin, PrintWriter jout) {
        int[] mole0 = IOUtils.read1DIntArray(jin, 4);
        int[] mole1 = IOUtils.read1DIntArray(jin, 4);
        int[] mole2 = IOUtils.read1DIntArray(jin, 4);
        int[] mole3 = IOUtils.read1DIntArray(jin, 4);

        int mnMoves = INF;
        int[][] pts = new int[4][];
        for(int i = 0; i < 4; i++) {
            pts[0] = rotate(mole0, i);
            for(int j = 0; j < 4; j++) {
                pts[1] = rotate(mole1, j);
                if(IsEqual(pts[0], pts[1])) continue;
                for(int k = 0; k < 4; k++) {
                    pts[2] = rotate(mole2, k);
                    if(IsEqual(pts[0], pts[2])) continue;
                    if(IsEqual(pts[1], pts[2])) continue;
                    for(int l = 0; l < 4; l++) {
                        pts[3] = rotate(mole3, l);
                        if(IsEqual(pts[0], pts[3])) continue;
                        if(IsEqual(pts[1], pts[3])) continue;
                        if(IsEqual(pts[2], pts[3])) continue;

                        long[] dist = new long[3];
                        dist[0] = sqDist(pts[0], pts[1]);
                        dist[1] = sqDist(pts[0], pts[2]);
                        dist[2] = sqDist(pts[0], pts[3]);

                        int[] index = IndexedSort(dist);

                        if(dist[index[1]] != dist[index[0]])
                            continue;

                        long[] odist = new long[3];
                        odist[0] = sqDist(pts[index[0] + 1], pts[index[1] + 1]);
                        odist[1] = sqDist(pts[index[2] + 1], pts[index[0] + 1]);
                        odist[2] = sqDist(pts[index[2] + 1], pts[index[1] + 1]);

                        if(odist[0] <= odist[1])
                            continue;
                        if(odist[2] != odist[1])
                            continue;
                        if(dist[index[0]] != odist[1])
                            continue;
                        if(dist[index[2]] != odist[0])
                            continue;

                        int moves = i + j + k + l;
                        if(moves < mnMoves) {
                            mnMoves = moves;
                        }
                    }
                }
            }
        }
        jout.println(mnMoves < INF? mnMoves : -1);
    }

    private boolean IsEqual(int[] pt0, int[] pt1) {
        return pt0[0] == pt1[0] && pt0[1] == pt1[1];
    }

    private int[] IndexedSort(long[] array) {
        int[] sol = new int[array.length];
        for(int i = 0; i < sol.length; i++) sol[i] = i;

        boolean change = true;
        while(change) {
            change = false;
            for(int i = 0; i + 1 < sol.length; i++) {
                if(array[sol[i]] > array[sol[i + 1]]) {
                    sol[i] ^= sol[i + 1];
                    sol[i + 1] ^= sol[i];
                    sol[i] ^= sol[i + 1];
                    change = true;
                }
            }
        }
        return sol;
    }

    private long sqDist(int[] pt1, int[] pt2) {
        int dx = pt1[0] - pt2[0];
        int dy = pt1[1] - pt2[1];

        return dx * 1L * dx + dy * 1L * dy;
    }

    private int[] rotate(int[] mole, int count) {
        int x1 = mole[0];
        int y1 = mole[1];
        int x0 = mole[2];
        int y0 = mole[3];

        int nx = x1 - x0;
        int ny = y1 - y0;
        for(int i = 0; i < count; i++) {
            int tx = -ny;
            int ty = nx;

            nx = tx;
            ny = ty;
        }
        int x2 = nx + x0;
        int y2 = ny + y0;

        return new int[]{x2, y2};
    }
}

class InputReader {
    private static final int bufferMaxLength = 1024;
    private InputStream in;
    private byte[] buffer;
    private int currentBufferSize;
    private int currentBufferTop;
    private static final String tokenizers = " \t\r\f\n";

    public InputReader(InputStream stream) {
        this.in = stream;
        buffer = new byte[bufferMaxLength];
        currentBufferSize = 0;
        currentBufferTop = 0;
    }

    private boolean refill() {
        try {
            this.currentBufferSize = this.in.read(this.buffer);
            this.currentBufferTop = 0;
        } catch(Exception e) {}
        return this.currentBufferSize > 0;
    }

    public String line() {
        StringBuffer tok = new StringBuffer();
        Byte first;
        while((first = readChar()) != null) {
            tok.append((char)first.byteValue());
            if((char)first.byteValue() == '\n')
                break;
        }
        return tok.toString();
    }

    public Byte readChar() {
        if(currentBufferTop < currentBufferSize) {
            return this.buffer[this.currentBufferTop++];
        } else {
            if(!this.refill()) {
                return null;
            } else {
                return readChar();
            }
        }
    }

    public String token()  {
        StringBuffer tok = new StringBuffer();
        Byte first;
        while((first = readChar()) != null && (tokenizers.indexOf((char) first.byteValue()) != -1));
        if(first == null) return null;
        tok.append((char)first.byteValue());
        while((first = readChar()) != null && (tokenizers.indexOf((char) first.byteValue()) == -1)) {
            tok.append((char)first.byteValue());
        }
        return tok.toString();
    }


    public String next() {
        return token();
    }

    public Integer int32() throws NumberFormatException {
        String tok = token();
        return tok == null? null : Integer.parseInt(tok);
    }

    public Long int64() throws NumberFormatException {
        String tok = token();
        return tok == null? null : Long.parseLong(tok);
    }
}

class IOUtils {
    public static int[] read1DIntArray(InputReader in, int size) {
        int[] arr = new int[size];
        for(int i = 0; i < size; i++) {
            arr[i] = in.int32();
        }
        return arr;
    }

    public static int[][] read2DIntArray(InputReader in, int rowSize, int colSize) {
        int[][] arr = new int[rowSize][];
        for(int i = 0; i < rowSize; i++) {
            arr[i] = IOUtils.read1DIntArray(in, colSize);
        }
        return arr;
    }
}

