#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <iostream>
#include <fstream>
#include <string>
#include <sstream>
#include <cmath>
#include <cstring>
#include <vector>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <queue>
#include <set>
#include <stack>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <complex>
#include <assert.h>

using namespace std;

#define F first
#define S second
#define PB push_back
#define MP make_pair
#define MT make_tuple
#define SQ(a) ((a)*(a))
#define X real()
#define Y imag()

#define F0R(i, a, b) for (int i=(a); i<(b); i++)
#define FOR(i, a) for (int i=0; i<(a); i++)
#define F0Rd(i,a,b) for (int i = (b)-1; i >= (a); i--)
#define FORd(i,a) for (int i = (a)-1; i >= 0; i--)

#define FAST ios::sync_with_stdio(0); cin.tie(0)
#define INF 1000000000
#define EPS 0.000000001

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef vector<pii> vp;
typedef complex<ll> point;

ll t;
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a%b);
}
int main() {
	FAST;
	cin >> t;
	FOR(i, t) {
		ll n;
		cin >> n;
		ll count1 = 0;
		ll count2 = 0;
		ll counter = 0;
		vector<pair<ll, ll>> vec;
		FOR(j, n) {
			ll x, y, u, v;
			cin >> x >> y >> u >> v;
			if (x == u) {
				if (y > v) count1++;
				else count2++;
			}
			else {
				ll g = gcd(abs(u - x), abs(v - y));
				vec.PB(MP((u - x) / g, (v - y) / g));
				//if (u - x <= 0 && v - y <= 0) {
				//	vec.PB(MP(-(u - x) / g, -(v - y) / g));
				//}
				//else if ((u - x >= 0 && (v - y) < 0)) {
				//	vec.PB(MP(-(u - x) / g, -(v - y) / g));
				//}
				//else {
				//	vec.PB(MP((u - x) / g, (v - y) / g));
				//}
			}
		}
		sort(vec.begin(), vec.end());
		FOR(i, vec.size()) {
			auto a = lower_bound(vec.begin(), vec.end(), MP(-vec[i].F, -vec[i].S));
			auto b = upper_bound(vec.begin(), vec.end(), MP(-vec[i].F, -vec[i].S));
			counter += b - a;
		}
		counter /= 2;
		counter += count1 * count2;
		cout << counter << "\n";
	}
	return 0;
}