#include <iostream>
#include <bits/stdc++.h>
typedef long long int ll;
using namespace std;
ll gcd(ll a, ll b){
    a = abs(a);
    b = abs(b);
    while(a>0 && b >0){
        if(a>b)a%=b;
        else b%=a;
    }
    return a+b;
}
void normalize(ll &a, ll &b){
    ll c = gcd(a,b);
    a/=c;
    b/=c;
}
int main() {
    int t;
    cin >> t;
    while(t--){
        int n;
        cin >> n;
        set<double> appear;
        map<pair<ll,ll>,ll> m;
        for(int i = 0; i <n ;i++){
            ll x,y,u,v;
            cin >> x>> y >> u >> v;
            ll fi = u-x;
            ll se = v-y;
            normalize(fi,se);
            m[{fi,se}]++;
        }
        long long int ans = 0;

        for(auto e: m){
           ans+=m[{e.first.first,e.first.second}]*m[{-e.first.first,-e.first.second}];
        }
        ans/=2;
        cout << ans << "\n";
    }

    return 0;
}
