// Never gonna give you up
// Never gonna let you down
// Never gonna run around and desert you
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define watch(x) cout <<(#x)<<" is "<<(x)<<endl
#define debug cout <<"hi"<<endl
#define fi first
#define se second
#define pf push_front
#define pb push_back
#define sz(a) a.size()
#define all(a) a.begin(),a.end()
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
ll gcd(ll a, ll b){return (b?gcd(b,a%b):a);}

void solve(){
    int n; cin >>n;
    map<pii,ll>mp; ll ans=0;
    while(n--){
        int x,y,u,v; cin >>x >>y >>u >>v;
        u-=x; v-=y;
        int g=abs(gcd(u,v));
        mp[{u/g,v/g}]++;
    }
    for(auto i:mp) ans+=i.se*mp[{-i.fi.fi,-i.fi.se}];
    cout <<ans/2<<'\n';
}

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    int T; cin >>T; while(T--)
    solve(); return 0;
}