#include<bits/stdc++.h> 
using namespace std; 
 
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL);
#define lli long long int
#define ld long double
#define pb push_back
#define pf push_front
#define mp make_pair
#define mt make_tuple
#define all(x) (x).begin(),(x).end()
#define pll pair<lli,lli>
#define ve vector<lli>
#define vep vector<pair<lli,lli> >
#define fr(i,a,n) for(lli i=a;i<(n);i++)
#define frx(i,a,n) for(lli i=a;i>(n);i--)
#define lb lower_bound
#define ub upper_bound
#define F first
#define S second
#define db(x) cout << "[ " << x << " ]" << endl
#define db2(x,y) cout<<"[ " <<x<<" "<<y<< " ]" <<endl
#define parr(arr,a,n) fr(i,a,n) cout<<arr[i]<<" "; cout<<endl
#define mem(a,x) memset(a,x,sizeof(a));
#define yes cout<<"YES"<<endl
#define no cout<<"NO"<<endl
 
lli quad(lli x,lli y){
    if(x>0 && y>0) return 1;
    if(x<0 && y>0) return 2;
    if(x<0 && y<0) return 3;
    if(x>0 && y<0) return 4;
    if(x>0 && y==0) return 5;
    if(x==0 && y>0) return 6;
    if(x<0 && y==0) return 7;
    if(x==0 && y<0) return 8;
    return 0;
}
 
lli oppquad(lli x,lli y){
    if(x>0 && y>0) return 3;
    if(x<0 && y>0) return 4;
    if(x<0 && y<0) return 1;
    if(x>0 && y<0) return 2;
    if(x>0 && y==0) return 7;
    if(x==0 && y>0) return 8;
    if(x<0 && y==0) return 5;
    if(x==0 && y<0) return 6;
    return 0;
}
ld mod(ld x){
    if(x>0)return x;
    return -x;
}
 
void solve(){
    lli n,ans=0;
    map<ld,lli> m[15];
    cin>>n;
    fr(i,0,n){
        ld x,y,u,v;
        cin>>x>>y>>u>>v;
        if(x!=u && y!=v){
            ld slope=mod((v-y)/(u-x));
            m[quad(u-x,v-y)][slope]++;
            ans+=m[oppquad(u-x,v-y)][slope];
            
        }
        else{
            m[quad(u-x,v-y)][0]++;
            ans+=m[oppquad(u-x,v-y)][0];
        }
    }
    cout<<ans<<endl;
}
 
int main(){
    fast;
    lli t=1;
    cin>>t;
    while(t--){
        solve();
    }
}
