
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
using namespace std;
const int maxn = 1e5 + 5;
typedef long long ll;
typedef pair<int,int> pii;
int n;
int x[maxn],y[maxn],u[maxn],v[maxn];
int gcd(int a,int b){
	if(b == 0) return a;
	return gcd(b,a%b);
}
map<pii,vector<int> > mp;
int main(){

   
	int cn;scanf("%d",&cn);
	while(cn --){
		scanf("%d",&n);
		mp.clear();
		for(int i = 0;i < n;i ++) scanf("%d%d%d%d",&x[i],&y[i],&u[i],&v[i]);
		for(int i = 0;i < n;i ++){
			u[i] -= x[i];v[i] -= y[i];
			int g = abs(gcd(u[i],v[i]));
			u[i] /= g;v[i] /= g;
			mp[make_pair(u[i],v[i])].push_back(i);
		}
		//for(int i = 0;i < n;i ++) printf("i = %d, %d %d\n",i,u[i],v[i]);
		ll ans =0;
		for(int i = 0;i < n;i ++){
			pii pr = make_pair(-u[i],-v[i]);
			if(mp.find(pr) != mp.end()) ans += mp[pr].size(); 
		}
		ans >>= 1;
		printf("%I64d\n",ans);
	}

	return 0;
}
