#include <bits/stdc++.h>

typedef long long ll;
#define FIN ios::sync_with_stdio(0);cout.tie(0);cin.tie(0)
#define forr(i,a,b) for(int i = (int)a; i < (int)b; i++)
#define forn(i,n) forr(i,0,n)
#define all(c) (c).begin(),(c).end()
#define DBG(x) cerr << #x << " = " << x << endl
#define RAYA cerr << "==================================" << endl

using namespace std;

ll mcd(ll a, ll b) {
  a = abs(a); b = abs(b);
  if(a == 0 && b == 0) return 1;
  while(a > 0 && b > 0) {
    if(a > b) a %= b;
    else b %= a;
  }
  return (a == 0 ? b : a);
}

struct chabon {
  ll x, y, vx, vy;
};

int main() {
  FIN;
  
  int t; cin >> t;
  while(t--) {
    int n; cin >> n;
    vector <chabon> v(n);
    forn(i,n) cin >> v[i].x >> v[i].y >> v[i].vx >> v[i].vy;
    map <pair<ll,ll>, ll> mapa;
    forn(i,n) {
      v[i].vx -= v[i].x; v[i].vy -= v[i].y;
      ll aux = mcd(v[i].vx,v[i].vy);
      v[i].vx /= aux, v[i].vy /= aux;
      mapa[{v[i].vx,v[i].vy}]++;
    }
    ll ans = 0;
    forn(i,n) {
      ll x = v[i].vx * -1, y = v[i].vy *= -1;
      ans += mapa[{x,y}];
    }
    ans /= 2;
    cout << ans << "\n";
  }
  
  return 0;
}
