    //जय श्री गणेश
#include <bits/stdc++.h>
#define ll long long int
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL);
#define pb push_back 
#define mp make_pair
#define ff first
#define ss second
#define pii pair<int,int> 
#define pll pair<ll,ll> 
#define vi vector<int> 
#define endl '\n'
#define vll vector<ll> 
#define MAX 1000000

using namespace std;

void init_code(){
    fastio;
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif 
}

ll gcd(ll a, ll b)
{
    if(b>a)
    return gcd(b,a) ; 
    if(b == 0)
    return a ; 
    return gcd(b,a%b)  ;
}

int main() 
{
  // your code goes here
  init_code() ; 
  int t ; 
  cin>>t ; 
  while(t--)
  {
    int n ; 
    cin>>n ;
    map<pll,ll> mp ; 
    for(int i = 0 ; i<n ;i++)
    {
      ll x,y,v,u ; 
      cin>>x>>y>>v>>u ; 
      pll p ; 
      p.first = v-x ; 
      p.second = u-y ; 
      if(p.first == 0 && p.second == 0)
      {
        p.first = 0 ; 
        p.second = 0 ; 
      }
      else if(p.first == 0)
      {
        p.second = p.second/abs(p.second) ; 

      }
      else if(p.second == 0)
      {
        p.first = p.first/abs(p.first) ; 
      }
      else
      {
        ll g = gcd(abs(p.first),abs(p.second)) ;
        p.first = p.first/g ; 
        p.second = p.second/g ;  
      }
      mp[p]++ ; 
    }
    ll ans = 0 ;
    for(auto x : mp)
    {
      pll p ;
      p.first = -x.first.first ; 
      p.second = -x.first.second ; 
      pll te ; 
      te.first = x.first.first ; 
      te.second = x.first.second ; 
      ans += mp[p]*mp[te]  ; 
      mp[p] = 0 ; 
      mp[te] = 0 ; 
    }
    cout<<ans<<endl;
  }

  
  
  return 0;
}