#include<bits/stdc++.h>
using namespace std;
#define int long long
#define N 100005
int read(){
	int w=0,f=1;
	char c=' ';
	while(c<'0'||c>'9')c=getchar(),f=c=='-'?-1:f;
	while(c>='0'&&c<='9')w=w*10+c-48,c=getchar();
	return w*f;
}
int T,n,ans;
double x[N],y[N],u[N],v[N];
map<double,int>mp[3];
signed main(){
	T=read();
	while(T--){
		mp[1].clear();
		mp[2].clear();
		n=read(),ans=0;
		int cnt1=0,cnt2=0;
		for(int i=1;i<=n;i++){
			x[i]=read(),y[i]=read(),u[i]=read(),v[i]=read();
			if(x[i]!=u[i]){
				if(x[i]>u[i])mp[1][(y[i]-v[i])/(x[i]-u[i])]++;
				else mp[2][(y[i]-v[i])/(x[i]-u[i])]++;
			}
			else{
				if(y[i]>v[i])cnt1++;
				else cnt2++;
			}
		}
		for(auto i:mp[1])
			ans+=i.second*mp[2][i.first];
		printf("%lld\n",ans+cnt1*cnt2);
	}
	return 0;
}