#include <bits/stdc++.h>
#include <math.h>
#define lli long long int
#include <limits.h>
#include <fstream>
#define F first
#define S second
#define PI 3.141592653589793238
#define pb push_back

using namespace std;

//doesn't work for arrays
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

const lli mod=1000000007;

lli gcd(lli a,lli b)
{
    if(a==0)
        return b;
    return gcd(b%a,a);
}

lli binpow(lli x,lli y,lli m)
{
    if (y==0)
        return 1;
    lli p=binpow(x,y/2,m)%m;
    p=(p*p)%m;
    if(y%2)
        return (x*p)%m;
    else
        return p;
}

lli modi(lli a,lli m)
{
    return binpow(a,m-2,m);
}

lli query(lli tree[],lli l,lli r)
{
    lli ans=0;
    while(l<r)
    {
        if(l%2)
        {
            ans=gcd(ans,tree[l]);
            l++;
        }
        if(r%2)
        {
            r--;
            ans=gcd(ans,tree[r]);
        }
        l/=2;
        r/=2;
    }
    return ans;
}

lli find_set(lli v,lli parent[]) {
    if (v==parent[v])
        return v;
    return parent[v]=find_set(parent[v],parent);
}

void union_sets(lli a, lli b,lli parent[]) {
    a=find_set(a,parent);
    b=find_set(b,parent);
    if(a!=b)
        parent[b]=a;
}

lli lca(lli a,lli b,vector<vector<lli>> &par,lli depth[])
{
    if(depth[a]<depth[b])
        swap(a,b);
    lli diff=depth[a]-depth[b],ct=0;
    while(diff)
    {
        if(diff%2)
        {
            a=par[ct][a];
        }
        ct++;
        diff/=2;
    }
    if(a==b)
        return a;
    for(lli i=19;i>=0;i--)
    {
        if(par[i][a]!=par[i][b])
        {
            a=par[i][a];
            b=par[i][b];
        }
    }
    return par[0][a];
}

//how to set precision for double
//cout<<fixed<<setprecision(10);



/*
//euler tour for subtrees

lli timer=0;

void dfs(lli v,lli par,vector<lli> g[],pair<lli,lli> range[],lli nw[],bool vis[])
{
    range[v].first=timer;
    nw[v]=timer;
    for(lli i=0;i<g[v].size();i++)
    {
        if(!vis[g[v][i]])
        {
            timer++;
            vis[g[v][i]]=1;
            dfs(g[v][i],v,g,range,nw,vis);
        }
    }
    range[v].second=timer;
}*/

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    lli i,j,tt=1,tc;
    cin>>tt;
    for(tc=1;tc<=tt;tc++)
    {
        //cout<<"Case #"<<tc<<": ";
        lli n,ans=0,temp,temp1,temp2;
        cin>>n;
        pair<lli,lli> a[n],b[n];
        for(i=0;i<n;i++)
        {
            cin>>a[i].first>>a[i].second>>b[i].first>>b[i].second;
        }
        map<pair<lli,lli>,lli> m;
        for(i=0;i<n;i++)
        {
            temp=gcd(abs(a[i].first-b[i].first),abs(a[i].second-b[i].second));
            temp1=(a[i].first-b[i].first)/temp;
            temp2=((a[i].second-b[i].second))/temp;
            m[{temp1,temp2}]++;
        }
        for(auto x:m)
        {
            ans+=(x.second*m[{-x.first.first,-x.first.second}]);
        }
        cout<<(ans)/2<<"\n";
    }
    return 0;
}
