#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define pll pair<ll,ll>
#define pii pair<int,int>
#define vll vector<ll>
#define vpll vector<pll>
#define fastio ios::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
double pi = acos(-1);
const double eps = 1e-9;
const int inf = 1e9 + 7;
const ll lnf = 1e18 + 7;
const int maxn = 2e5 + 10;
ll mod = 1e9 + 7;

map<int, map<int, int> >mp;

int gcd(int a, int b)
{
	return b ? gcd(b, a % b) : a;
}

int main()
{
	fastio;
	int t;
	cin >> t;
	while (t--)
	{
		mp.clear();
		int n;
		cin >> n;
		ll ans = 0;
		while (n--)
		{
			int x, y, a, b;
			cin >> x >> y >> a >> b;
			//cout << x - a << " " << y - b << endl;
			int g = abs(gcd(x - a, y - b));
			ans += mp[(x - a) / g][(y - b) / g];
			mp[(a - x) / g][(b - y) / g]++;
		}
		cout << ans << endl;
	}
	return 0;

}
