#include <bits/stdc++.h>
using namespace std;
using ll = long long;

struct P {
    ll x, y;
};
int main() {
    int t;
    cin >> t;
    while (t--) {
        P p[4], c[4], v[4][4];
        for (int i = 0; i < 4; i++) {
            cin >> p[i].x >> p[i].y >> c[i].x >> c[i].y;
            v[i][0] = p[i];
            for (int j = 1; j < 4; j++) {
                auto a = v[i][j - 1];
                v[i][j] = {c[i].x - (a.y - c[i].y), c[i].y + (a.x - c[i].x)};
            }
        }
        int ans = 100;
        for (int mask = 0; mask < 256; mask++) {
            int z = mask, cost = 0;
            P a[4];
            for (int i = 0; i < 4; i++) {
                int k = z % 4;
                z /= 4;
                cost += k;
                a[i] = v[i][k];
            }
            vector<ll> d;
            for (int i = 0; i < 4; i++)
                for (int j = 0; j < i; j++) {
                    ll x = a[i].x - a[j].x, y = a[i].y - a[j].y;
                    d.push_back(x * x + y * y);
                }
            sort(d.begin(), d.end());
            if (d[0] > 0 && d[0] == d[3] && d[4] == d[5] && d[4] == 2 * d[0])
                ans = min(ans, cost);
        }
        cout << (ans == 100 ? -1 : ans) << '\n';
    }
}
