#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <map>

using namespace std;

int gcd(int a, int b) {
    while (b != 0) {
        int r = a % b;
        a = b;
        b = r;
    }
    return a;
}

int n;

int main() {
    int oo;
    cin >> oo;
    for (int o = 0; o < oo; ++o) {
        scanf("%d", &n);
        map<pair<int, int>, int> mm;
        mm.clear();
        for (int  i = 0; i < n; ++i) {
            int x, y, u, v;
            scanf("%d%d%d%d", &x, &y, &u, &v);
            int uu = u - x;
            int vv = v - y;
            
            if (uu == 0) vv /= abs(vv);
            else if (vv == 0) uu /= abs(uu);
            else {
                int g = gcd(uu, vv);
                uu /= abs(g);
                vv /= abs(g);
            }
            mm[make_pair(uu, vv)]++;
        }
        long long res = 0LL;
        for (auto it = mm.begin(); it != mm.end(); ++it) {
            pair<int, int> a = it->first;
            int b = it->second;
            auto c = make_pair(-a.first, -a.second);

            if (mm.find(c) != mm.end()) {
                res += (long long) b * mm[c];
            }
        }
        printf("%lld\n", res/2);
    }
}