#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define reps(i,s,n) for(int i=(s); i<(n); i++)
#define all(v) v.begin(),v.end()
#define outve(v) for(auto i : v) cout << i << " ";cout << endl
#define outmat(v) for(auto i : v){for(auto j : i) cout << j << " ";cout << endl;}
#define in(n,v) for(int i=0; i<(n); i++){cin >> v[i];}
#define out(n) cout << (n) << endl
#define fi first
#define se second
#define pb push_back
#define si(v) int(v.size())
#define len(v) int(v.length())
#define lob(v,n) lower_bound(all(v),n)
#define lobi(v,n) lower_bound(all(v),n) - v.begin()
#define upb(v,n) upper_bound(all(v),n)
#define upbi(v,n) upper_bound(all(v),n) - v.begin()
#define mod 1000000007
#define infi 1010000000
#define infl 1100000000000000000
#define cyes cout << "Yes" << endl
#define cno cout << "No" << endl
#define csp << " " <<
#define outset(n) cout << fixed << setprecision(n);
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vd = vector<double>;
using vvd = vector<vector<double>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
template<typename T> using ve = vector<T>;
template<typename T> using pq2 = priority_queue<T>;
template<typename T> using pq1 = priority_queue<T,vector<T>,greater<T>>;
template<typename T> bool chmax(T &a, T b) {if(a < b) {a = b;return 1;}return 0;}
template<typename T> bool chmin(T &a, T b) {if(a > b) {a = b;return 1;}return 0;}


template <typename T> T gcd(T a, T b) {if(b == 0) return a;return gcd(b,a%b);}



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

    int t;
    cin >> t;
    
    while (t--) {
        int N;
        cin >> N;
        map<pii,ll> A1,A2,A3,A4;
        ll a1 = 0,a2 = 0,a3 = 0,a4 = 0;
        ll ans = 0;
        
        rep(i,N){
            int a,b,c,d;
            cin >> a >> b >> c >> d;
            c -= a;
            d -= b;
            int aa = gcd(abs(c),abs(d));
            
            if(c == 0) {
                if(d > 0) a1++;
                else a2++;
            }else if(d == 0){
                if(c > 0) a3++;
                else a4++;
            }else if(c > 0 && d > 0){
                A1[{c/aa, d/aa}]++;
            }else if(c > 0 && d < 0){
                A2[{c/aa, -d/aa}]++;
            }else if(c < 0 && d > 0){
                A3[{-c/aa, d/aa}]++;
            }else{
                A4[{-c/aa, -d/aa}]++;
            }
        }
        
        ans += a1*a2+a3*a4;
        for (auto p : A1) {
            ans += p.se*A4[p.fi];
        }
        for (auto p : A2) {
            ans += p.se*A3[p.fi];
        }
        
        cout << ans << endl;
        
        
    }
    
    
    

    return 0;
}
