#include<bits/stdc++.h>

using namespace std;

struct line{
	long long x;
	long long y;
	line(long long _x,long long _y) {
		x = _x;y = _y;
	}
};
int qu(line a) {
	long long y = a.y;
	long long x = a.x;
	if(y>=0 && x>0) {
		return 0;
	} else if(y>0 && x<=0) {
		return 1;
	} else if(y <= 0 && x < 0){
		return 2;
	} else {
		return 3;
	}
}
bool operator < (const line &x,const line &y) {
	if(qu(x) != qu(y)) {
		return qu(x) < qu(y);
	} else {
		return x.y * y.x < x.x * y.y;
	}
	
}
map<line,int>mp;
void solve(){
	mp.clear();
	int n;
	scanf("%d",&n);
	long long ans = 0;
	for(int i = 1; i <= n;i++) {
		long long a,b,c,d;
		scanf("%lld%lld%lld%lld",&a,&b,&c,&d);
		long long t1 = c - a;
		long long t2 = d - b;
		if(t1==0 && t2==0) {
			continue;
		}
		
		/*
		if(t1 < 0) {
			t1 = -t1;
			t2 = -t2;
		}
		*/
		ans += mp[line(-t1,-t2)];	
		mp[line(t1,t2)]++;
//	printf("~%lld\n",ans);
	}
	printf("%lld\n",ans);
}

int main(){
	int T;
	scanf("%d",&T);
	while(T--) {
		solve();
	}
}