#include <iostream>
#include <map>

using namespace std;

int n;
pair<long long, long long> a[100000];

long long gcd(long long a, long long b)
{
    /* GCD(0, b) == b; GCD(a, 0) == a,
       GCD(0, 0) == 0 */
    if (a == 0)
        return b;
    if (b == 0)
        return a;
 
    /*Finding K, where K is the
      greatest power of 2
      that divides both a and b. */
    long long k;
    for (k = 0; ((a | b) & 1) == 0; ++k) 
    {
        a >>= 1;
        b >>= 1;
    }
 
    /* Dividing a by 2 until a becomes odd */
    while ((a & 1) == 0)
        a >>= 1;
 
    /* From here on, 'a' is always odd. */
    do
    {
        /* If b is even, remove all factor of 2 in b */
        while ((b & 1) == 0)
            b >>= 1;
 
        /* Now a and b are both odd.
           Swap if necessary so a <= b,
           then set b = b - a (which is even).*/
        if (a > b)
            swap(a, b); // Swap u and v.
 
        b = (b - a);
    }while (b != 0);
 
    /* restore common factors of 2 */
    return a << k;
}

template <typename T> int sgn(T val) {
    return (T(0) < val) - (val < T(0));
}

long long absll(long long x){
	if(x < 0){
		return -x;
	}
	return x;
}

void solve(){
	map<pair<long long, long long>, long long> mapping;

	cin >> n;

	//cout << "n " << n << endl;
	for(int i = 0; i < n; i++){
		long long x = 0, y = 0, u = 0, v = 0;
		cin >> x >> y >> u >> v;

		long long deltax = u - x;
		long long deltay = v - y;

		//cout << "got up to gcd" << endl;
		long long div = gcd(absll(deltax), absll(deltay));

		deltax /= div;
		deltay /= div;

		a[i].first = deltax;
		a[i].second = deltay;

		mapping[a[i]]++;

		//cout << "read" << endl;
	}

	long long ans = 0;
	for(auto x: mapping){
		//cout << "(" << x.first.first << ", " << x.first.second << ") " << ": " << x.second << endl;
		auto opposite = pair<long long, long long>(-x.first.first, -x.first.second);
		if(mapping.find(opposite) != mapping.end()){
			long long count = mapping[opposite];

			ans += count * x.second;
		}
	}

	cout << (ans / 2) << "\n";

}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);

	int t = 0;
	cin >> t;

	while(t --> 0){
		solve();
	}
}