#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <unordered_map>
#include <cmath>
#include <queue>
#include <iomanip>
#include <bitset>
#include <stack>
#include <memory.h>
#include <list>
#include <numeric>
#include <functional>
#include <complex>
#include <cassert>
#include <regex>
#include <random>
#include <fstream>

#define ll long long
#define ld long double
#define ull unsigned ll
#define mp(xx, yy) make_pair(xx, yy)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define pii pair<int,int> 
#define pll pair<ll, ll> 
#define vi vector<int>
#define vll vector<ll>
#define vpii vector<pii>
#define vpll vector<pll>
#define vvi vector<vector<int>>
#define forn(it,from,to) for(int (it)=from; (it)<to; (it)++)
//#define endl '\n'
ld pi = acos(-1.0);
const int mod = 1e9 + 7;
using namespace std;

int gcd(int x, int y) {
	if (y == 0) return x;
	return gcd(y, x%y);
}

int main() {
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#else
	//freopen("hyperdrome.in", "r", stdin);
	//freopen("hyperdrome.out", "w", stdout);
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
#endif
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	cout.precision(20); cout.setf(ios::fixed);

	int ttt;
	cin >> ttt;
	while(ttt--){
		int n;
		cin >> n;
		map<pii, ll> cnt;
		forn(i, 0, n) {
			int x1, y1, x2, y2;
			cin >> x1 >> y1 >> x2 >> y2;
			int dx = x2 - x1, dy = y2 - y1;
			int g = gcd(abs(dx), abs(dy));
			dx /= g, dy /= g;
			cnt[{dx, dy}]++;
		}
		ll ans = 0;
		for (auto &t : cnt) {
			ans += t.second * cnt[{-t.first.first, -t.first.second}];
		}
		cout << ans / 2 << '\n';
	}

	return 0;
}