#include<bits/stdc++.h>
using namespace std;

#define PB push_back
#define MP make_pair
#define F first
#define S second
#define SZ(a) (int)(a.size())
#define ALL(a) a.begin(),a.end()
#define SET(a,b) memset(a,b,sizeof(a))
#define off ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
typedef pair<int,int>   II;
typedef vector< II >      VII;
typedef vector<int>     VI;
typedef vector< VI > 	VVI;
typedef long long int 	LL;
typedef vector<LL> 		VL;
#define si(n) cin>>n
#define dout(n) cout<<n<<"\n"
#define DRT() int t; si(t); while(t--)
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
//# define M_PI           3.14159265358979323846264338327950288
// DSU

void IO(){
	#ifndef ONLINE_JUDGE
    freopen("../input.txt", "r", stdin);
    freopen("../output.txt", "w", stdout);
	#endif
	mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
	off;
}
LL gcd(LL x, LL y){
	return y == 0 ? x : gcd(y, x % y);
}
int main(){
	IO();
	DRT(){
		LL n;cin>>n;
		map<pair<LL, LL> , LL> cnt;
		LL x,y,u,v;
		LL ans = 0;
		rep(i,0,n){
			cin>>x>>y>>u>>v;
			LL num = x - u;
			LL deo = y - v;
			LL g;
			if(num == 0){
				if(deo < 0){
					cnt[{0, 1}]++;
					ans += cnt[{0, -1}];
				}
				else{
					cnt[{0, -1}]++;
					ans += cnt[{0, 1}];
				}
			}
			else if(deo == 0){
				if(num < 0){
					cnt[{-1, 0}]++;
					ans += cnt[{1, 0}];
				}
				else{
					cnt[{1, 0}]++;
					ans += cnt[{-1, 0}];
				}
			}
			else{
				if(abs(num) > abs(deo))
					g = gcd(abs(num), abs(deo));
				else
					g = gcd(abs(deo), abs(num));
				num /= g;
				deo /= g;
				ans += cnt[{-num, -deo}];
				cnt[{num, deo}]++;
			}
		}
		dout(ans);
	}
	return 0;
}