There are $n$ persons located on a plane. The $i$-th person is located at the point $(x_i, y_i)$ and initially looks at the point $(u_i, v_i)$.

At the same moment of time, all persons will start to rotate clockwise synchronously with the same angular speed. They will rotate until they do one full $360$-degree turn.

It is said that persons $A$ and $B$ made eye contact if person $A$ looks in person $B$'s direction at the same moment when person $B$ looks in person $A$'s direction. If there is a person $C$ located between persons $A$ and $B$, that will not obstruct $A$ and $B$ from making eye contact. A person can make eye contact with more than one person at the same time.

Calculate the number of pairs of persons that will make eye contact at least once during the rotation (including the initial moment).


-----Input-----

The first line contains one integer $t$ ($1 \le t \le 10^4$) — the number of test cases.

The first line of each test case contains a single integer $n$ ($1 \le n \le 10^5$) — the number of persons. The following $n$ lines describe persons, each line containing four space-separated integers $x_i, y_i, u_i, v_i$ ($|x_i|, |y_i|, |u_i|, |v_i| \le 10^9$; $x_i \ne u_i$ or $y_i \ne v_i$), where ($x_i, y_i$) are the coordinates of the point where the $i$-th person is located and ($u_i$, $v_i$) are the coordinates of the point that the $i$-th person looks at initially. Each person's location is unique in each test case.

The sum of $n$ over all test cases does not exceed $10^5$.


-----Output-----

For each test case, print one integer — the number of pairs of persons who will make eye contact at least once during the rotation, including the initial moment.


-----Examples-----

Input
3
2
0 0 0 1
1 0 2 0
3
0 0 1 1
1 1 0 0
1 0 2 0
6
0 0 0 1
1 0 1 2
2 0 2 3
3 0 3 -5
4 0 4 -5
5 0 5 -5
Output
0
1
9


-----Note-----

None

Source: codeforces | Difficulty: MEDIUM_HARD
Tags: Geometry

Number theory

String algorithms


Solutions:
import collections, math
t = int(input())
for _ in range(t):
	n = int(input())
	cnt = collections.defaultdict(int)
	for _ in range(n):
		(x, y, u, v) = map(int, input().split())
		(du, dv) = (u - x, v - y)
		g = math.gcd(du, dv)
		cnt[du // g, dv // g] += 1
	ans = 0
	for (du, dv) in tuple(cnt.keys()):
		ans += cnt[du, dv] * cnt[-du, -dv]
		cnt[du, dv] = 0
		cnt[-du, -dv] = 0
	print(ans)


import os, sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
from math import sqrt, ceil, gcd
for _ in range(int(input())):
	d = dict()
	z1 = z2 = 0
	i1 = i2 = 0
	for _ in range(int(input())):
		(x1, y1, x2, y2) = map(int, input().split())
		if x1 == x2:
			if y2 - y1 > 0:
				i1 += 1
			else:
				i2 += 1
		elif y1 == y2:
			if x1 - x2 > 0:
				z1 += 1
			else:
				z2 += 1
		else:
			z = gcd(y2 - y1, x2 - x1)
			t1 = (y2 - y1) // z
			t2 = (x2 - x1) // z
			if t2 < 0:
				t1 *= -1
				t2 *= -1
			t = (t1, t2)
			if x2 - x1 < 0:
				d[t] = d.get(t, [0, 0])
				d[t][0] += 1
			else:
				d[t] = d.get(t, [0, 0])
				d[t][1] += 1
	ans = 0
	for i in d:
		ans += d[i][0] * d[i][1]
	print(ans + z1 * z2 + i1 * i2)


import math
import random
import heapq, bisect
import sys
from collections import deque, defaultdict
from fractions import Fraction
import sys
import threading
from collections import defaultdict
threading.stack_size(10 ** 8)
mod = 10 ** 9 + 7
mod1 = 998244353
import os
import sys
from io import BytesIO, IOBase
sys.setrecursionlimit(300000)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

class TreeNode:

	def __init__(self, k, v):
		self.key = k
		self.value = v
		self.left = None
		self.right = None
		self.parent = None
		self.height = 1
		self.num_left = 1
		self.num_total = 1

class AvlTree:

	def __init__(self):
		self._tree = None

	def add(self, k, v):
		if not self._tree:
			self._tree = TreeNode(k, v)
			return
		node = self._add(k, v)
		if node:
			self._rebalance(node)

	def _add(self, k, v):
		node = self._tree
		while node:
			if k < node.key:
				if node.left:
					node = node.left
				else:
					node.left = TreeNode(k, v)
					node.left.parent = node
					return node.left
			elif node.key < k:
				if node.right:
					node = node.right
				else:
					node.right = TreeNode(k, v)
					node.right.parent = node
					return node.right
			else:
				node.value = v
				return

	@staticmethod
	def get_height(x):
		return x.height if x else 0

	@staticmethod
	def get_num_total(x):
		return x.num_total if x else 0

	def _rebalance(self, node):
		n = node
		while n:
			lh = self.get_height(n.left)
			rh = self.get_height(n.right)
			n.height = max(lh, rh) + 1
			balance_factor = lh - rh
			n.num_total = 1 + self.get_num_total(n.left) + self.get_num_total(n.right)
			n.num_left = 1 + self.get_num_total(n.left)
			if balance_factor > 1:
				if self.get_height(n.left.left) < self.get_height(n.left.right):
					self._rotate_left(n.left)
				self._rotate_right(n)
			elif balance_factor < -1:
				if self.get_height(n.right.right) < self.get_height(n.right.left):
					self._rotate_right(n.right)
				self._rotate_left(n)
			else:
				n = n.parent

	def _remove_one(self, node):
		replacement = node.left or node.right
		if node.parent:
			if AvlTree._is_left(node):
				node.parent.left = replacement
			else:
				node.parent.right = replacement
			replacement.parent = node.parent
			node.parent = None
		else:
			self._tree = replacement
			replacement.parent = None
		node.left = None
		node.right = None
		node.parent = None
		self._rebalance(replacement)

	def _remove_leaf(self, node):
		if node.parent:
			if AvlTree._is_left(node):
				node.parent.left = None
			else:
				node.parent.right = None
			self._rebalance(node.parent)
		else:
			self._tree = None
		node.parent = None
		node.left = None
		node.right = None

	def remove(self, k):
		node = self._get_node(k)
		if not node:
			return
		if AvlTree._is_leaf(node):
			self._remove_leaf(node)
			return
		if node.left and node.right:
			nxt = AvlTree._get_next(node)
			node.key = nxt.key
			node.value = nxt.value
			if self._is_leaf(nxt):
				self._remove_leaf(nxt)
			else:
				self._remove_one(nxt)
			self._rebalance(node)
		else:
			self._remove_one(node)

	def get(self, k):
		node = self._get_node(k)
		return node.value if node else -1

	def _get_node(self, k):
		if not self._tree:
			return None
		node = self._tree
		while node:
			if k < node.key:
				node = node.left
			elif node.key < k:
				node = node.right
			else:
				return node
		return None

	def get_at(self, pos):
		x = pos + 1
		node = self._tree
		while node:
			if x < node.num_left:
				node = node.left
			elif node.num_left < x:
				x -= node.num_left
				node = node.right
			else:
				return (node.key, node.value)
		raise IndexError('Out of ranges')

	@staticmethod
	def _is_left(node):
		return node.parent.left and node.parent.left == node

	@staticmethod
	def _is_leaf(node):
		return node.left is None and node.right is None

	def _rotate_right(self, node):
		if not node.parent:
			self._tree = node.left
			node.left.parent = None
		elif AvlTree._is_left(node):
			node.parent.left = node.left
			node.left.parent = node.parent
		else:
			node.parent.right = node.left
			node.left.parent = node.parent
		bk = node.left.right
		node.left.right = node
		node.parent = node.left
		node.left = bk
		if bk:
			bk.parent = node
		node.height = max(self.get_height(node.left), self.get_height(node.right)) + 1
		node.num_total = 1 + self.get_num_total(node.left) + self.get_num_total(node.right)
		node.num_left = 1 + self.get_num_total(node.left)

	def _rotate_left(self, node):
		if not node.parent:
			self._tree = node.right
			node.right.parent = None
		elif AvlTree._is_left(node):
			node.parent.left = node.right
			node.right.parent = node.parent
		else:
			node.parent.right = node.right
			node.right.parent = node.parent
		bk = node.right.left
		node.right.left = node
		node.parent = node.right
		node.right = bk
		if bk:
			bk.parent = node
		node.height = max(self.get_height(node.left), self.get_height(node.right)) + 1
		node.num_total = 1 + self.get_num_total(node.left) + self.get_num_total(node.right)
		node.num_left = 1 + self.get_num_total(node.left)

	@staticmethod
	def _get_next(node):
		if not node.right:
			return node.parent
		n = node.right
		while n.left:
			n = n.left
		return n

class SegmentTree1:

	def __init__(self, data, default=2 ** 51, func=lambda a, b: a & b):
		self._default = default
		self._func = func
		self._len = len(data)
		self._size = _size = 1 << (self._len - 1).bit_length()
		self.data = [default] * (2 * _size)
		self.data[_size:_size + self._len] = data
		for i in reversed(range(_size)):
			self.data[i] = func(self.data[i + i], self.data[i + i + 1])

	def __delitem__(self, idx):
		self[idx] = self._default

	def __getitem__(self, idx):
		return self.data[idx + self._size]

	def __setitem__(self, idx, value):
		idx += self._size
		self.data[idx] = value
		idx >>= 1
		while idx:
			self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
			idx >>= 1

	def __len__(self):
		return self._len

	def query(self, start, stop):
		if start == stop:
			return self.__getitem__(start)
		stop += 1
		start += self._size
		stop += self._size
		res = self._default
		while start < stop:
			if start & 1:
				res = self._func(res, self.data[start])
				start += 1
			if stop & 1:
				stop -= 1
				res = self._func(res, self.data[stop])
			start >>= 1
			stop >>= 1
		return res

	def __repr__(self):
		return 'SegmentTree({0})'.format(self.data)

class SegmentTree:

	def __init__(self, data, default=0, func=lambda a, b: max(a, b)):
		self._default = default
		self._func = func
		self._len = len(data)
		self._size = _size = 1 << (self._len - 1).bit_length()
		self.data = [default] * (2 * _size)
		self.data[_size:_size + self._len] = data
		for i in reversed(range(_size)):
			self.data[i] = func(self.data[i + i], self.data[i + i + 1])

	def __delitem__(self, idx):
		self[idx] = self._default

	def __getitem__(self, idx):
		return self.data[idx + self._size]

	def __setitem__(self, idx, value):
		idx += self._size
		self.data[idx] = value
		idx >>= 1
		while idx:
			self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
			idx >>= 1

	def __len__(self):
		return self._len

	def query(self, start, stop):
		if start == stop:
			return self.__getitem__(start)
		stop += 1
		start += self._size
		stop += self._size
		res = self._default
		while start < stop:
			if start & 1:
				res = self._func(res, self.data[start])
				start += 1
			if stop & 1:
				stop -= 1
				res = self._func(res, self.data[stop])
			start >>= 1
			stop >>= 1
		return res

	def __repr__(self):
		return 'SegmentTree({0})'.format(self.data)

class Factorial:

	def __init__(self, MOD):
		self.MOD = MOD
		self.factorials = [1, 1]
		self.invModulos = [0, 1]
		self.invFactorial_ = [1, 1]

	def calc(self, n):
		if n <= -1:
			print('Invalid argument to calculate n!')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		if n < len(self.factorials):
			return self.factorials[n]
		nextArr = [0] * (n + 1 - len(self.factorials))
		initialI = len(self.factorials)
		prev = self.factorials[-1]
		m = self.MOD
		for i in range(initialI, n + 1):
			prev = nextArr[i - initialI] = prev * i % m
		self.factorials += nextArr
		return self.factorials[n]

	def inv(self, n):
		if n <= -1:
			print('Invalid argument to calculate n^(-1)')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		p = self.MOD
		pi = n % p
		if pi < len(self.invModulos):
			return self.invModulos[pi]
		nextArr = [0] * (n + 1 - len(self.invModulos))
		initialI = len(self.invModulos)
		for i in range(initialI, min(p, n + 1)):
			next = -self.invModulos[p % i] * (p // i) % p
			self.invModulos.append(next)
		return self.invModulos[pi]

	def invFactorial(self, n):
		if n <= -1:
			print('Invalid argument to calculate (n^(-1))!')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		if n < len(self.invFactorial_):
			return self.invFactorial_[n]
		self.inv(n)
		nextArr = [0] * (n + 1 - len(self.invFactorial_))
		initialI = len(self.invFactorial_)
		prev = self.invFactorial_[-1]
		p = self.MOD
		for i in range(initialI, n + 1):
			prev = nextArr[i - initialI] = prev * self.invModulos[i % p] % p
		self.invFactorial_ += nextArr
		return self.invFactorial_[n]

class Combination:

	def __init__(self, MOD):
		self.MOD = MOD
		self.factorial = Factorial(MOD)

	def ncr(self, n, k):
		if k < 0 or n < k:
			return 0
		k = min(k, n - k)
		f = self.factorial
		return f.calc(n) * f.invFactorial(max(n - k, k)) * f.invFactorial(min(k, n - k)) % self.MOD

def powm(a, n, m):
	if a == 1 or n == 0:
		return 1
	if n % 2 == 0:
		s = powm(a, n // 2, m)
		return s * s % m
	else:
		return a * powm(a, n - 1, m) % m

def sort_list(list1, list2):
	zipped_pairs = zip(list2, list1)
	z = [x for (_, x) in sorted(zipped_pairs)]
	return z

def product(l):
	por = 1
	for i in range(len(l)):
		por *= l[i]
	return por

def binarySearchCount(arr, n, key):
	left = 0
	right = n - 1
	count = 0
	while left <= right:
		mid = int((right + left) / 2)
		if arr[mid] < key:
			count = mid + 1
			left = mid + 1
		else:
			right = mid - 1
	return count

def countdig(n):
	c = 0
	while n > 0:
		n //= 10
		c += 1
	return c

def binary(x, length):
	y = bin(x)[2:]
	return y if len(y) >= length else '0' * (length - len(y)) + y

def countGreater(arr, n, k):
	l = 0
	r = n - 1
	leftGreater = n
	while l <= r:
		m = int(l + (r - l) / 2)
		if arr[m] >= k:
			leftGreater = m
			r = m - 1
		else:
			l = m + 1
	return n - leftGreater
for ik in range(int(input())):
	d = defaultdict(int)
	for i in range(int(input())):
		(a, b, c, d1) = map(int, input().split())
		x = c - a
		y = d1 - b
		gc = math.gcd(x, y)
		x //= gc
		y //= gc
		d[x, y] += 1
	done = set()
	ans = 0
	for i in d:
		if i in done:
			continue
		(a, b) = i
		j = (-a, -b)
		if j not in d:
			continue
		if a == 0 and b == 0:
			ans += d[i] * (d[i] - 1) // 2
		else:
			ans += d[i] * d[j]
		done.add(i)
		done.add(j)
	print(ans)


from sys import stdin, stdout
from math import floor, gcd, fabs, factorial, fmod, sqrt, inf, log, atan
from collections import defaultdict as dd, deque
from heapq import merge, heapify, heappop, heappush, nsmallest
from bisect import bisect_left as bl, bisect_right as br, bisect
mod = pow(10, 9) + 7
mod2 = 998244353

def inp():
	return stdin.readline().strip()

def out(var, end='\n'):
	stdout.write(str(var) + '\n')

def outa(*var, end='\n'):
	stdout.write(' '.join(map(str, var)) + end)

def lmp():
	return list(mp())

def mp():
	return map(int, inp().split())

def smp():
	return map(str, inp().split())

def l1d(n, val=0):
	return [val for i in range(n)]

def l2d(n, m, val=0):
	return [l1d(n, val) for j in range(m)]

def remadd(x, y):
	return 1 if x % y else 0

def ceil(a, b):
	return (a + b - 1) // b

def isprime(x):
	if x <= 1:
		return False
	if x in (2, 3):
		return True
	if x % 2 == 0:
		return False
	for i in range(3, int(sqrt(x)) + 1, 2):
		if x % i == 0:
			return False
	return True

def slope(x1, y1, x2, y2):
	d = x2 - x1
	n = y2 - y1
	if d == 0:
		return str(inf) if n > 0 else str(inf) + 'i'
	if n == 0:
		return '0' if d > 0 else '0i'
	return str(n / d) if n > 0 else str(n / d) + 'i'
for _ in range(int(inp())):
	n = int(inp())
	ml = []
	md = {}
	ans = []
	rans = 0
	for i in range(n):
		(x, y, u, v) = mp()
		s = slope(u, v, x, y)
		if s[-1] == 'i':
			if s[:-1] not in md:
				md[s[:-1]] = 1
			else:
				md[s[:-1]] += 1
		else:
			ans.append(s)
	for i in ans:
		rans += md[i] if i in md else 0
	print(rans)


from __future__ import division, print_function
from fractions import Fraction
import sys
import os
from io import BytesIO, IOBase
from itertools import *
import bisect
from heapq import *
from math import ceil, floor
from copy import *
from collections import deque, defaultdict
from collections import Counter as counter
from itertools import combinations
from itertools import permutations as permutate
from bisect import bisect_left as bl
from operator import *
from bisect import bisect_right as br
from bisect import bisect
BUFSIZE = 8192
from sys import stderr

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
from types import GeneratorType

def iterative(f, stack=[]):

	def wrapped_func(*args, **kwargs):
		if stack:
			return f(*args, **kwargs)
		to = f(*args, **kwargs)
		while True:
			if type(to) is GeneratorType:
				stack.append(to)
				to = next(to)
				continue
			stack.pop()
			if not stack:
				break
			to = stack[-1].send(to)
		return to
	return wrapped_func

class SortedList:

	def __init__(self, iterable=[], _load=200):
		values = sorted(iterable)
		self._len = _len = len(values)
		self._load = _load
		self._lists = _lists = [values[i:i + _load] for i in range(0, _len, _load)]
		self._list_lens = [len(_list) for _list in _lists]
		self._mins = [_list[0] for _list in _lists]
		self._fen_tree = []
		self._rebuild = True

	def _fen_build(self):
		self._fen_tree[:] = self._list_lens
		_fen_tree = self._fen_tree
		for i in range(len(_fen_tree)):
			if i | i + 1 < len(_fen_tree):
				_fen_tree[i | i + 1] += _fen_tree[i]
		self._rebuild = False

	def _fen_update(self, index, value):
		if not self._rebuild:
			_fen_tree = self._fen_tree
			while index < len(_fen_tree):
				_fen_tree[index] += value
				index |= index + 1

	def _fen_query(self, end):
		if self._rebuild:
			self._fen_build()
		_fen_tree = self._fen_tree
		x = 0
		while end:
			x += _fen_tree[end - 1]
			end &= end - 1
		return x

	def _fen_findkth(self, k):
		_list_lens = self._list_lens
		if k < _list_lens[0]:
			return (0, k)
		if k >= self._len - _list_lens[-1]:
			return (len(_list_lens) - 1, k + _list_lens[-1] - self._len)
		if self._rebuild:
			self._fen_build()
		_fen_tree = self._fen_tree
		idx = -1
		for d in reversed(range(len(_fen_tree).bit_length())):
			right_idx = idx + (1 << d)
			if right_idx < len(_fen_tree) and k >= _fen_tree[right_idx]:
				idx = right_idx
				k -= _fen_tree[idx]
		return (idx + 1, k)

	def _delete(self, pos, idx):
		_lists = self._lists
		_mins = self._mins
		_list_lens = self._list_lens
		self._len -= 1
		self._fen_update(pos, -1)
		del _lists[pos][idx]
		_list_lens[pos] -= 1
		if _list_lens[pos]:
			_mins[pos] = _lists[pos][0]
		else:
			del _lists[pos]
			del _list_lens[pos]
			del _mins[pos]
			self._rebuild = True

	def _loc_left(self, value):
		if not self._len:
			return (0, 0)
		_lists = self._lists
		_mins = self._mins
		(lo, pos) = (-1, len(_lists) - 1)
		while lo + 1 < pos:
			mi = lo + pos >> 1
			if value <= _mins[mi]:
				pos = mi
			else:
				lo = mi
		if pos and value <= _lists[pos - 1][-1]:
			pos -= 1
		_list = _lists[pos]
		(lo, idx) = (-1, len(_list))
		while lo + 1 < idx:
			mi = lo + idx >> 1
			if value <= _list[mi]:
				idx = mi
			else:
				lo = mi
		return (pos, idx)

	def _loc_right(self, value):
		if not self._len:
			return (0, 0)
		_lists = self._lists
		_mins = self._mins
		(pos, hi) = (0, len(_lists))
		while pos + 1 < hi:
			mi = pos + hi >> 1
			if value < _mins[mi]:
				hi = mi
			else:
				pos = mi
		_list = _lists[pos]
		(lo, idx) = (-1, len(_list))
		while lo + 1 < idx:
			mi = lo + idx >> 1
			if value < _list[mi]:
				idx = mi
			else:
				lo = mi
		return (pos, idx)

	def add(self, value):
		_load = self._load
		_lists = self._lists
		_mins = self._mins
		_list_lens = self._list_lens
		self._len += 1
		if _lists:
			(pos, idx) = self._loc_right(value)
			self._fen_update(pos, 1)
			_list = _lists[pos]
			_list.insert(idx, value)
			_list_lens[pos] += 1
			_mins[pos] = _list[0]
			if _load + _load < len(_list):
				_lists.insert(pos + 1, _list[_load:])
				_list_lens.insert(pos + 1, len(_list) - _load)
				_mins.insert(pos + 1, _list[_load])
				_list_lens[pos] = _load
				del _list[_load:]
				self._rebuild = True
		else:
			_lists.append([value])
			_mins.append(value)
			_list_lens.append(1)
			self._rebuild = True

	def discard(self, value):
		_lists = self._lists
		if _lists:
			(pos, idx) = self._loc_right(value)
			if idx and _lists[pos][idx - 1] == value:
				self._delete(pos, idx - 1)

	def remove(self, value):
		_len = self._len
		self.discard(value)
		if _len == self._len:
			raise ValueError('{0!r} not in list'.format(value))

	def pop(self, index=-1):
		(pos, idx) = self._fen_findkth(self._len + index if index < 0 else index)
		value = self._lists[pos][idx]
		self._delete(pos, idx)
		return value

	def bisect_left(self, value):
		(pos, idx) = self._loc_left(value)
		return self._fen_query(pos) + idx

	def bisect_right(self, value):
		(pos, idx) = self._loc_right(value)
		return self._fen_query(pos) + idx

	def count(self, value):
		return self.bisect_right(value) - self.bisect_left(value)

	def __len__(self):
		return self._len

	def __getitem__(self, index):
		(pos, idx) = self._fen_findkth(self._len + index if index < 0 else index)
		return self._lists[pos][idx]

	def __delitem__(self, index):
		(pos, idx) = self._fen_findkth(self._len + index if index < 0 else index)
		self._delete(pos, idx)

	def __contains__(self, value):
		_lists = self._lists
		if _lists:
			(pos, idx) = self._loc_left(value)
			return idx < len(_lists[pos]) and _lists[pos][idx] == value
		return False

	def __iter__(self):
		return (value for _list in self._lists for value in _list)

	def __reversed__(self):
		return (value for _list in reversed(self._lists) for value in reversed(_list))

	def __repr__(self):
		return 'SortedList({0})'.format(list(self))
mod = 1000000007

def testcase(t):
	for p in range(t):
		solve()

def pow(x, y, p):
	res = 1
	x = x % p
	if x == 0:
		return 0
	while y > 0:
		if y & 1 == 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res
from functools import reduce

def factors(n):
	return set(reduce(list.__add__, ([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0)))

def gcd(a, b):
	if a == b:
		return a
	while b > 0:
		(a, b) = (b, a % b)
	return a

def prefix_sum(ar):
	return list(accumulate(ar))

def suffix_sum(ar):
	return list(accumulate(ar[::-1]))[::-1]

def N():
	return int(inp())

def YES():
	print('YES')

def NO():
	print('NO')

def Yes():
	print('Yes')

def No():
	print('No')
from collections import defaultdict

def numberOfSetBits(i):
	i = i - (i >> 1 & 1431655765)
	i = (i & 858993459) + (i >> 2 & 858993459)
	return ((i + (i >> 4) & 252645135) * 16843009 & 4294967295) >> 24

class MergeFind:

	def __init__(self, n):
		self.parent = list(range(n))
		self.size = [1] * n
		self.num_sets = n

	def find(self, a):
		to_update = []
		while a != self.parent[a]:
			to_update.append(a)
			a = self.parent[a]
		for b in to_update:
			self.parent[b] = a
		return self.parent[a]

	def merge(self, a, b):
		a = self.find(a)
		b = self.find(b)
		if a == b:
			return
		if self.size[a] < self.size[b]:
			(a, b) = (b, a)
		self.num_sets -= 1
		self.parent[b] = a
		self.size[a] += self.size[b]

	def set_size(self, a):
		return self.size[self.find(a)]

	def __len__(self):
		return self.num_sets

def lcm(a, b):
	return abs(a // gcd(a, b) * b)

def comb(n, r):
	if n < r:
		return 0
	else:
		return fac[n] * (finv[r] * finv[n - r] % mod) % mod

def inp():
	return sys.stdin.readline().rstrip('\r\n')

def out(var):
	sys.stdout.write(str(var))

def lis():
	return list(map(int, inp().split()))

def stringlis():
	return list(map(str, inp().split()))

def sep():
	return map(int, inp().split())

def strsep():
	return map(str, inp().split())

def fsep():
	return map(float, inp().split())

def nextline():
	out('\n')

def arr1d(n, v):
	return [v] * n

def arr2d(n, m, v):
	return [[v] * m for _ in range(n)]

def arr3d(n, m, p, v):
	return [[[v] * p for _ in range(m)] for i in range(n)]

def solve():
	n = N()
	d = defaultdict(int)
	for _ in range(n):
		(x1, y1, u1, v1) = sep()
		U = u1 - x1
		V = v1 - y1
		aU = abs(U)
		aV = abs(V)
		g = gcd(aU, aV)
		U //= g
		V //= g
		d[U, V] += 1
	ans = 0
	KEYS = list(d.keys())
	for i in KEYS:
		(a, b) = i
		(am, bm) = (-a, -b)
		ans += d[a, b] * d[am, bm]
	print(ans // 2)
testcase(int(inp()))


from math import gcd

def solve(L):
	d = {}
	count = 0
	L.sort()
	for (x, y, u, v) in L:
		u -= x
		v -= y
		g = abs(gcd(u, v))
		if g != 0:
			u //= g
			v //= g
		else:
			u //= abs(u + v)
			v //= abs(u + v)
		if (-u, -v) in d:
			count += d[-u, -v]
		if (u, v) not in d:
			d[u, v] = 1
		else:
			d[u, v] += 1
	print(count)
t = int(input())
for i in range(t):
	n = int(input())
	L = [tuple(map(int, input().split())) for i in range(n)]
	solve(L)


from math import sqrt
from collections import defaultdict

def roundedunitvector(vec):
	first = vec[0]
	second = vec[1]
	mag = sqrt(first * first + second * second)
	return (round(first / mag, 10), round(second / mag, 10))
t = int(input())
for dsklfj in range(t):
	n = int(input())
	count = 0
	d = defaultdict(lambda : 0)
	for i in range(n):
		splitted = [int(amit) for amit in input().split(' ')]
		x = splitted[0]
		y = splitted[1]
		u = splitted[2]
		v = splitted[3]
		unit = roundedunitvector((u - x, v - y))
		d[unit] += 1
		negatedUnit = (-1 * unit[0], -1 * unit[1])
		if negatedUnit in d:
			count += d[negatedUnit]
	print(count)


import math
for _ in range(int(input())):
	l1 = []
	n = int(input())
	for i in range(n):
		(x, y, u, v) = [int(_) for _ in input().split()]
		if x == u:
			if v > y:
				l1.append((0, 1))
			else:
				l1.append((0, -1))
		elif y == v:
			if u > x:
				l1.append((1, 0))
			else:
				l1.append((-1, 0))
		else:
			l1.append(((u - x) // math.gcd(v - y, u - x), (v - y) // math.gcd(v - y, u - x)))
	if n == 1:
		print(0)
		continue
	l1.sort()
	shit = 0
	dict1 = {}
	for i in range(n - 1):
		if l1[i] != l1[i + 1]:
			shit += 1
			dict1[l1[i]] = shit
			shit = 0
		else:
			shit += 1
	if l1[-1] != l1[-2]:
		dict1[l1[-1]] = 1
	else:
		dict1[l1[-1]] = shit + 1
	ans = 0
	for i in dict1.keys():
		try:
			ans += dict1[i] * dict1[-i[0], -i[1]]
		except:
			pass
	print(ans // 2)


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):

	def __init__(self, file):
		self.newlines = 0
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline()

def RL():
	return map(int, sys.stdin.readline().split())

def RLL():
	return list(map(int, sys.stdin.readline().split()))

def N():
	return int(input())

def S():
	return input().strip()

def print_list(l):
	print(' '.join(map(str, l)))
from math import gcd
from collections import Counter
for _ in range(N()):
	dic = Counter()
	for _ in range(N()):
		(x, y, u, v) = RL()
		(dx, dy) = (u - x, v - y)
		if dx == 0:
			dic[0, 1 if dy > 0 else -1] += 1
		elif dy == 0:
			dic[1 if dx > 0 else -1, 0] += 1
		else:
			t = gcd(dx, dy)
			dic[dx // t, dy // t] += 1
	print(sum((dic[x, y] * dic[-x, -y] for (x, y) in dic)) >> 1)


import sys, math
input = sys.stdin.readline
from collections import Counter
for _ in range(int(input())):
	n = int(input())
	A = [list(map(int, input().split())) for _ in range(n)]
	cnt = Counter()
	ans = 0
	for (a, b, c, d) in A:
		x = c - a
		y = d - b
		g = math.gcd(x, y)
		x //= g
		y //= g
		ans += cnt[-x, -y]
		cnt[x, y] += 1
	print(ans)


import sys
LI = lambda : list(map(int, sys.stdin.readline().split()))
MI = lambda : map(int, sys.stdin.readline().split())
SI = lambda : sys.stdin.readline().strip('\n')
II = lambda : int(sys.stdin.readline())
from math import gcd
for _ in range(II()):
	cnt = {}
	for __ in range(II()):
		(x, y, u, v) = MI()
		(x, y) = (u - x, v - y)
		v = gcd(x, y)
		(x, y) = (x // v, y // v)
		cnt[x, y] = cnt.get((x, y), 0) + 1
	ans = 0
	for (x, y) in cnt:
		try:
			ans += cnt[x, y] * cnt[-x, -y]
		except:
			pass
	print(ans // 2)


import math
from sys import stdin
tt = int(stdin.readline())
for loop in range(tt):
	n = int(stdin.readline())
	dic = {}
	ans = 0
	for i in range(n):
		(x, y, u, v) = map(int, stdin.readline().split())
		u -= x
		v -= y
		g = abs(math.gcd(u, v))
		u //= g
		v //= g
		if (-1 * u, -1 * v) in dic:
			ans += dic[-1 * u, -1 * v]
		if (u, v) not in dic:
			dic[u, v] = 0
		dic[u, v] += 1
	print(ans)


import sys
from math import gcd
input = sys.stdin.readline
for _ in range(int(input())):
	vects = []
	case = dict()
	for _ in range(int(input())):
		(x, y, u, v) = list(map(int, input().split()))
		if x == u:
			vect = (0, (v - y) // abs(v - y))
		elif y == v:
			vect = ((u - x) // abs(u - x), 0)
		else:
			g = gcd(x - u, v - y)
			vect = ((u - x) // g, (v - y) // g)
		if vect in case:
			case[vect] += 1
		else:
			case[vect] = 1
	s = 0
	for ((a, b), val) in case.items():
		s += val * case.get((-a, -b), 0)
	print(s // 2)


import os
import sys
import math
from io import BytesIO, IOBase
from fractions import Fraction
import collections
from itertools import permutations
from collections import defaultdict
from collections import deque
import threading
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

class SegmentTree:

	def __init__(self, data, default=10 ** 10, func=lambda a, b: min(a, b)):
		self._default = default
		self._func = func
		self._len = len(data)
		self._size = _size = 1 << (self._len - 1).bit_length()
		self.data = [default] * (2 * _size)
		self.data[_size:_size + self._len] = data
		for i in reversed(range(_size)):
			self.data[i] = func(self.data[i + i], self.data[i + i + 1])

	def __delitem__(self, idx):
		self[idx] = self._default

	def __getitem__(self, idx):
		return self.data[idx + self._size]

	def __setitem__(self, idx, value):
		idx += self._size
		self.data[idx] = value
		idx >>= 1
		while idx:
			self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
			idx >>= 1

	def __len__(self):
		return self._len

	def query(self, start, stop):
		if start == stop:
			return self.__getitem__(start)
		stop += 1
		start += self._size
		stop += self._size
		res = self._default
		while start < stop:
			if start & 1:
				res = self._func(res, self.data[start])
				start += 1
			if stop & 1:
				stop -= 1
				res = self._func(res, self.data[stop])
			start >>= 1
			stop >>= 1
		return res

	def __repr__(self):
		return 'SegmentTree({0})'.format(self.data)
MOD = 10 ** 9 + 7

class Factorial:

	def __init__(self, MOD):
		self.MOD = MOD
		self.factorials = [1, 1]
		self.invModulos = [0, 1]
		self.invFactorial_ = [1, 1]

	def calc(self, n):
		if n <= -1:
			print('Invalid argument to calculate n!')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		if n < len(self.factorials):
			return self.factorials[n]
		nextArr = [0] * (n + 1 - len(self.factorials))
		initialI = len(self.factorials)
		prev = self.factorials[-1]
		m = self.MOD
		for i in range(initialI, n + 1):
			prev = nextArr[i - initialI] = prev * i % m
		self.factorials += nextArr
		return self.factorials[n]

	def inv(self, n):
		if n <= -1:
			print('Invalid argument to calculate n^(-1)')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		p = self.MOD
		pi = n % p
		if pi < len(self.invModulos):
			return self.invModulos[pi]
		nextArr = [0] * (n + 1 - len(self.invModulos))
		initialI = len(self.invModulos)
		for i in range(initialI, min(p, n + 1)):
			next = -self.invModulos[p % i] * (p // i) % p
			self.invModulos.append(next)
		return self.invModulos[pi]

	def invFactorial(self, n):
		if n <= -1:
			print('Invalid argument to calculate (n^(-1))!')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		if n < len(self.invFactorial_):
			return self.invFactorial_[n]
		self.inv(n)
		nextArr = [0] * (n + 1 - len(self.invFactorial_))
		initialI = len(self.invFactorial_)
		prev = self.invFactorial_[-1]
		p = self.MOD
		for i in range(initialI, n + 1):
			prev = nextArr[i - initialI] = prev * self.invModulos[i % p] % p
		self.invFactorial_ += nextArr
		return self.invFactorial_[n]

class Combination:

	def __init__(self, MOD):
		self.MOD = MOD
		self.factorial = Factorial(MOD)

	def ncr(self, n, k):
		if k < 0 or n < k:
			return 0
		k = min(k, n - k)
		f = self.factorial
		return f.calc(n) * f.invFactorial(max(n - k, k)) * f.invFactorial(min(k, n - k)) % self.MOD
mod = 10 ** 9 + 7
omod = 998244353
for _ in range(int(input())):
	d = defaultdict(int)
	n = int(input())
	s = set()
	for i in range(n):
		(x, y, u, v) = map(int, input().split())
		x1 = u - x
		y1 = v - y
		g = math.gcd(abs(x1), abs(y1))
		x1 //= g
		y1 //= g
		d[x1, y1] += 1
		s.add((x1, y1))
	res = 0
	for i in s:
		(x, y) = i
		c1 = d[x, y]
		c2 = d[-x, -y]
		res += c1 * c2
	res //= 2
	print(res)


from sys import stdin, stdout
from collections import defaultdict
import math

def main():
	t = int(stdin.readline())
	for _ in range(t):
		n = int(stdin.readline())
		rec = defaultdict(int)
		cnt = 0
		for _ in range(n):
			(x, y, u, v) = list(map(int, stdin.readline().split()))
			(X, Y) = (u - x, v - y)
			if X == 0:
				Y = 1 if Y > 0 else -1
			elif Y == 0:
				X = 1 if X > 0 else -1
			else:
				gcd = math.gcd(X, Y)
				X = int(X / gcd)
				Y = int(Y / gcd)
			rec[X, Y] += 1
			cnt += rec[-X, -Y]
		stdout.write(str(cnt) + '\n')
main()


from collections import Counter
from math import gcd
if True:
	for _ in range(int(input())):
		dct = Counter()
		n = int(input())
		for _ in range(n):
			(x, y, u, v) = map(int, input().split())
			if u - x and v - y:
				r = gcd(u - x, v - y)
				dct[(u - x) // r, (v - y) // r] += 1
			elif not u - x:
				dct[0, 1 if v - y > 0 else -1] += 1
			else:
				dct[1 if u - x > 0 else -1, 0] += 1
		ans = 0
		for i in dct:
			x = list(i)
			(x[0], x[1]) = (-x[0], -x[1])
			x = tuple(x)
			ans += dct[i] * dct[x]
		print(ans // 2)


import sys
from collections import defaultdict

def load_sys():
	return sys.stdin.readlines()

def load_local():
	with open('input.txt', 'r') as f:
		input = f.readlines()
	return input

def ft(persons):
	ctr = defaultdict(int)
	ans = 0
	for (x, y, u, v) in persons:
		d = ((u - x) ** 2 + (v - y) ** 2) ** 0.5
		nx = round((u - x) / d, 10)
		ny = round((v - y) / d, 10)
		ans += ctr[-nx, -ny]
		ctr[nx, ny] += 1
	return ans
input = load_sys()
idx = 1
while idx < len(input):
	N = int(input[idx].strip())
	idx += 1
	case = []
	for j in range(N):
		input[idx + j] = input[idx + j].split()
		case.append([int(x) for x in input[idx + j]])
	print(ft(case))
	idx += N


from math import gcd
t = int(input())
for i in range(t):
	n = int(input())
	(w, iota) = ([], [])
	q = {}
	for j in range(n):
		w.append([int(k) for k in input().split()])
		c = (w[-1][2] - w[-1][0], w[-1][3] - w[-1][1])
		if c[0] == 0:
			c = (0, c[1] // abs(c[1]))
			iota.append(c)
		elif c[1] == 0:
			c = (c[0] // abs(c[0]), 0)
			iota.append(c)
		else:
			y = gcd(c[0], c[1])
			c = (c[0] // y, c[1] // y)
			iota.append(c)
		if c in q:
			q[c] += 1
		else:
			q[c] = 1
	res = 0
	for j in iota:
		if (-j[0], -j[1]) in q:
			res += q[-j[0], -j[1]]
	print(res // 2)


from math import inf

def slope(v):
	return inf if v[0] == 0 else v[1] / v[0]

def which_quarter(v):
	if v[0] > 0:
		if v[1] > 0:
			return 1
		else:
			return 4
	elif v[0] < 0:
		if v[1] < 0:
			return 3
		else:
			return 2
	else:
		return 1 if v[1] > 0 else 3

def make_vector_with_slope(tup):
	vector = (tup[2] - tup[0], tup[3] - tup[1])
	return (vector[0], vector[1], slope(vector), which_quarter(vector))

def count_parallels(v):
	ans = 0
	for i in range(len(v)):
		if v[i][3] > 2:
			ans += 1
	return ans
t = int(input())
for i in range(t):
	n = int(input())
	points = []
	for j in range(n):
		points.append(tuple(map(int, input().split(' '))))
	vectors = list(map(lambda tup: make_vector_with_slope(tup), points))
	vectors.sort(key=lambda v: v[2])
	ans = 0
	previous_index = 0
	for j in range(1, n):
		if vectors[j][2] != vectors[previous_index][2]:
			parallels = count_parallels(vectors[previous_index:j])
			ans += parallels * (j - previous_index - parallels)
			previous_index = j
	parallels = count_parallels(vectors[previous_index:])
	ans += parallels * (n - previous_index - parallels)
	print(ans)


from sys import stdin
t = int(stdin.readline())
for _ in range(t):
	n = int(stdin.readline())
	di = {}
	for i in range(n):
		(x, y, u, v) = map(int, stdin.readline().split())
		if u - x == 0:
			o = 'A'
			sign = (v - y) // abs(v - y)
		else:
			o = (v - y) / (u - x)
			sign = (u - x) // abs(u - x)
		if o not in di:
			di[o] = [0, 0]
		if sign == -1:
			di[o][0] += 1
		else:
			di[o][1] += 1
	tot = 0
	for i in di:
		tot += di[i][0] * di[i][1]
	print(tot)


from collections import defaultdict
from math import gcd
import sys
input = sys.stdin.readline
out = []
for _ in range(int(input())):
	n = int(input())
	dir = defaultdict(int)
	out.append(0)
	for _ in range(n):
		(a, b, x, y) = map(int, input().split())
		dx = x - a
		dy = y - b
		g = gcd(dx, dy)
		dx //= g
		dy //= g
		out[-1] += dir[dx, dy]
		dir[-dx, -dy] += 1
print('\n'.join(map(str, out)))


import sys, os, io
from collections import defaultdict
from math import gcd
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
for _ in range(int(input())):
	n = int(input())
	vect = defaultdict(lambda : 0)
	for i in range(n):
		(x, y, u, v) = [int(i) for i in input().split()]
		vv = [u - x, v - y]
		if vv[0] == 0:
			vv = [0, vv[1] // abs(vv[1])]
		elif vv[1] == 0:
			vv = [vv[0] // abs(vv[0]), 0]
		else:
			g = gcd(vv[0], vv[1])
			vv = [vv[0] // g, vv[1] // g]
		vv = tuple(vv)
		vect[vv] += 1
	ans = 0
	for i in vect:
		a = (-i[0], -i[1])
		if a in vect:
			ans += vect[i] * vect[a]
	print(ans // 2)


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
from math import gcd as GCD
from collections import Counter
for j in range(int(input())):
	n = int(input())
	ans = 0
	count = Counter()
	for s in range(n):
		(a, b, c, d) = map(int, input().split())
		x = c - a
		y = d - b
		gcd = GCD(x, y)
		x //= gcd
		y //= gcd
		ans += count[-x, -y]
		count[x, y] += 1
	print(ans)


import math

def hash(x, y, u, v):
	g = math.gcd(u - x, v - y)
	return ((u - x) // g, (v - y) // g)
t = int(input())
for case in range(t):
	n = int(input())
	d = {}
	for p in range(n):
		x = hash(*[int(s) for s in input().split(' ')])
		if x in d:
			d[x] += 1
		else:
			d[x] = 1
	cnt = 0
	for k in d:
		z = (-k[0], -k[1])
		if z in d:
			cnt += d[k] * d[z]
	cnt //= 2
	print(cnt)


from collections import defaultdict
import math
for i1 in range(int(input())):
	l = []
	for i in range(int(input())):
		(a, b, c, d) = map(int, input().split())
		check = math.gcd(a - c, b - d)
		tupple = ((a - c) // check, (b - d) // check)
		l.append(tupple)
	dict = defaultdict(int)
	for i in l:
		dict[i] += 1
	ans = 0
	for (i, j) in dict.items():
		(a, b) = i
		check = 0
		if (-a, -b) in dict.keys():
			check = dict[-a, -b]
		ans += j * check
	print(ans // 2)


import sys
input = sys.stdin.readline
from sys import stdin, stdout
from collections import defaultdict, Counter
M = 10 ** 9 + 7
from fractions import Fraction

def main():
	for _ in range(int(input())):
		dp = defaultdict(int)
		dn = defaultdict(int)
		(zp, zn, ip, ine) = (0, 0, 0, 0)
		n = int(input())
		for j in range(n):
			(x, y, u, v) = [int(j) for j in input().split()]
			if x == u:
				if v - y > 0:
					ip += 1
				else:
					ine += 1
			elif y == v:
				if u - x > 0:
					zp += 1
				else:
					zn += 1
			else:
				a = Fraction(v - y, u - x)
				if v - y > 0:
					dp[a] += 1
				else:
					dn[a] += 1
		ans = ip * ine + zp * zn
		for i in dp:
			ans += dp[i] * dn[i]
		print(ans)
main()


from collections import defaultdict
import sys
input = sys.stdin.buffer.readline

def multiLineArrayPrint(arr):
	print('\n'.join([str(x) for x in arr]))

def gcd(x, y):
	while y != 0:
		(x, y) = (y, x % y)
	return x
t = int(input())
allAns = []
for _ in range(t):
	n = int(input())
	gradientCnts = defaultdict(lambda : 0)
	faceUpCnts = 0
	faceDownCnts = 0
	ans = 0
	for __ in range(n):
		(x, y, u, v) = [int(x) for x in input().split()]
		dy = v - y
		dx = u - x
		if dx != 0:
			divisor = gcd(abs(dy), abs(dx))
			dy //= divisor
			dx //= divisor
			ans += gradientCnts[-dx, -dy]
			gradientCnts[dx, dy] += 1
		else:
			dy //= abs(dy)
			ans += gradientCnts[-dy]
			gradientCnts[dy] += 1
	allAns.append(ans)
multiLineArrayPrint(allAns)


import os
import sys
from io import BytesIO, IOBase
import threading
from bisect import bisect_right
from math import gcd, log
from collections import Counter, defaultdict
from pprint import pprint
from itertools import permutations

def main():
	n = int(input())
	dct = defaultdict(int)
	ans = 0
	for i in range(n):
		(a, b, c, d) = map(int, input().split())
		a1 = a - c
		a2 = b - d
		dis = a1 ** 2 + a2 ** 2
		g1 = gcd(dis, a1 ** 2)
		g2 = gcd(dis, a2 ** 2)
		ans += dct[-a1 * abs(a1) // g1, dis // g1, dis // g2, -a2 * abs(a2) // g2]
		dct[a1 * abs(a1) // g1, dis // g1, dis // g2, a2 * abs(a2) // g2] += 1
	print(ans)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
for _ in range(int(input())):
	main()


from collections import Counter
import math
for ad in range(int(input())):
	n = int(input())
	x = []
	z = []
	for i in range(n):
		(a, b, c, d) = list(map(int, input().split()))
		if a - c == 0:
			if d > b:
				x.append(12345)
			else:
				x.append(-12345)
		elif b - d == 0:
			if c > a:
				x.append(123456)
			else:
				x.append(-123456)
		else:
			k = (b - d) / (a - c)
			if k > 0:
				if b - d < 0 and a - c < 0:
					x.append(-k)
				else:
					x.append(k)
			elif a - c < 0:
				z.append(k)
			else:
				z.append(-k)
	c = Counter(x)
	d = Counter(z)
	ans = 0
	y = sorted(c.keys())
	zz = sorted(d.keys())
	for i in y:
		if i < 0:
			ans += c[i] * c[-i]
		else:
			break
	for i in zz:
		if i < 0:
			ans += d[i] * d[-i]
		else:
			break
	print(ans)


from sys import stdin
from math import inf
input = stdin.readline

def read_num():
	return int(input())

def read_nums():
	return map(int, input().split())

def sign(x):
	return 0 if x == 0 else 1 if x > 0 else -1

class Man:

	def __init__(self, x, y, u, v):
		self.dx = abs(u - x)
		self.dy = abs(v - y)
		self.sign_x = sign(u - x)
		self.sign_y = sign(v - y)
		self.ratio = self.dx / self.dy if self.dy != 0 else inf

	def __repr__(self) -> str:
		return f'{self.dx} {self.dy} {self.sign_x} {self.sign_y} {self.ratio}'

	def same_angle(self, other):
		return self.dx * other.dy == self.dy * other.dx

def process_counts(counts):
	total = 0
	pairs = ([(1, 1), (-1, -1)], [(1, -1), (-1, 1)], [(0, 1), (0, -1)], [(1, 0), (-1, 0)])
	for (pair, anti_pair) in pairs:
		total += counts.get(pair, 0) * counts.get(anti_pair, 0)
	return total

def calculate(n, a):
	a.sort(key=lambda man: man.ratio)
	total_count = 0
	prev = a[0]
	counts = {}
	for man in a:
		if not man.same_angle(prev):
			total_count += process_counts(counts)
			counts = {}
			prev = man
		key = (man.sign_x, man.sign_y)
		counts[key] = counts.get(key, 0) + 1
	total_count += process_counts(counts)
	return total_count

def main():
	t = read_num()
	for _ in range(t):
		n = read_num()
		a = [Man(*read_nums()) for __ in range(n)]
		print(calculate(n, a))
main()


import sys
from collections import defaultdict
input = sys.stdin.readline

def ri():
	return [int(i) for i in input().split()]
mods = [1000003, 1000033]

def mod_inverse(a, m):
	a = a % m
	if a == 0:
		return 0
	else:
		return (1 - mod_inverse(m % a, a) * m) // a % m

def id(uu, vv):
	if uu > 0 and vv > 0:
		return 0
	elif uu > 0 and vv < 0:
		return 1
	elif uu < 0 and vv > 0:
		return 2
	else:
		return 3

def main():
	t = ri()[0]
	for _ in range(t):
		n = ri()[0]
		d = [defaultdict(int) for _ in range(4)]
		(up, un) = (0, 0)
		(vp, vn) = (0, 0)
		for i in range(n):
			(x, y, u, v) = ri()
			u -= x
			v -= y
			d_id = id(u, v)
			if u == 0:
				if v > 0:
					vp += 1
				else:
					vn += 1
				continue
			if v == 0:
				if u > 0:
					up += 1
				else:
					un += 1
			v_1 = [mod_inverse(v, m) for m in mods]
			hashes = tuple((u * v_1[i] % mods[i] for i in range(len(mods))))
			d[d_id][hashes] += 1
		res = 0
		for (k, v) in d[0].items():
			res += v * d[3][k]
		for (k, v) in d[1].items():
			res += v * d[2][k]
		res += up * un + vp * vn
		print(res)
main()


import math
import sys
input = sys.stdin.readline
from collections import Counter, defaultdict, deque

def f(n, vec):
	d = {}
	ans = 0
	for i in range(n):
		if vec[i][0] == 0:
			if vec[i][1] > 0:
				if (0, 1) not in d.keys():
					d[0, 1] = 1
				else:
					d[0, 1] += 1
			elif vec[i][1] < 0:
				if (0, -1) not in d.keys():
					d[0, -1] = 1
				else:
					d[0, -1] += 1
		elif vec[i][1] == 0:
			if vec[i][0] > 0:
				if (1, 0) not in d.keys():
					d[1, 0] = 1
				else:
					d[1, 0] += 1
			elif vec[i][0] < 0:
				if (-1, 0) not in d.keys():
					d[-1, 0] = 1
				else:
					d[-1, 0] += 1
		else:
			gcd = math.gcd(vec[i][0], vec[i][1])
			a = vec[i][0] // gcd
			b = vec[i][1] // gcd
			if (a, b) not in d.keys():
				d[a, b] = 1
			else:
				d[a, b] += 1
	for (x, y) in d.keys():
		ans += d[x, y] * d.get((-x, -y), 0)
	return ans // 2
t = int(input())
result = []
for i in range(t):
	n = int(input())
	vec = []
	for i in range(n):
		(x, y, u, v) = list(map(int, input().split()))
		vec.append((u - x, v - y))
	result.append(f(n, vec))
for i in range(t):
	print(result[i])


for _ in range(int(input())):
	n = int(input())
	d = {'infi': [0, 0]}
	ans = 0
	for nn in range(n):
		(x, y, u, v) = map(int, input().split(' '))
		if u - x == 0:
			if v - y < 0:
				d['infi'][0] += 1
			else:
				d['infi'][1] += 1
		else:
			s = (v - y) / (u - x)
			if s not in d:
				d[s] = [0, 0]
			if u - x < 0:
				d[s][0] += 1
			else:
				d[s][1] += 1
	for i in d:
		ans += d[i][0] * d[i][1]
	print(ans)


import os, sys
from io import BytesIO, IOBase
from collections import Counter
from math import gcd

def main():
	for _ in range(int(input())):
		dct = Counter()
		n = int(input())
		for _ in range(n):
			(x, y, u, v) = map(int, input().split())
			if u - x and v - y:
				r = gcd(u - x, v - y)
				dct[(u - x) // r, (v - y) // r] += 1
			elif not u - x:
				dct[0, 1 if v - y > 0 else -1] += 1
			else:
				dct[1 if u - x > 0 else -1, 0] += 1
		ans = 0
		for i in dct:
			x = list(i)
			(x[0], x[1]) = (-x[0], -x[1])
			x = tuple(x)
			ans += dct[i] * dct[x]
		print(ans // 2)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


import sys
LI = lambda : list(map(int, sys.stdin.readline().split()))
MI = lambda : map(int, sys.stdin.readline().split())
SI = lambda : sys.stdin.readline().strip('\n')
II = lambda : int(sys.stdin.readline())
from math import gcd
for _ in range(II()):
	ln = set()
	cnt = {}
	for __ in range(II()):
		(x, y, u, v) = MI()
		(x, y) = (u - x, v - y)
		v = gcd(x, y)
		(x, y) = (x // v, y // v)
		ln.add((x, y))
		cnt[x, y] = cnt.get((x, y), 0) + 1
	ans = 0
	for (x, y) in ln:
		if (-x, -y) in ln:
			ans += cnt[x, y] * cnt[-x, -y]
	print(ans // 2)


from sys import stdin
from math import gcd
from collections import Counter
input = stdin.readline
t = int(input())
for _ in range(t):
	n = int(input())
	p = [[int(x) for x in input().split()] for _ in range(n)]
	d = []
	for (x, y, u, v) in p:
		a = u - x
		b = v - y
		c = gcd(a, b)
		a //= c
		b //= c
		d.append((a, b))
	e = Counter(d)
	ans = 0
	for (i, c1) in e.items():
		c2 = e[-i[0], -i[1]]
		ans += c1 * c2
	ans //= 2
	print(ans)


from collections import defaultdict
import sys
input = sys.stdin.buffer.readline

def multiLineArrayPrint(arr):
	print('\n'.join([str(x) for x in arr]))

def gcd(x, y):
	while y != 0:
		(x, y) = (y, x % y)
	return x
t = int(input())
allAns = []
for _ in range(t):
	n = int(input())
	gradientCnts = defaultdict(lambda : 0)
	faceUpCnts = 0
	faceDownCnts = 0
	for __ in range(n):
		(x, y, u, v) = [int(x) for x in input().split()]
		dy = v - y
		dx = u - x
		if dx != 0:
			divisor = gcd(abs(dy), abs(dx))
			dy //= divisor
			dx //= divisor
			gradientCnts[dx, dy] += 1
		else:
			dy //= abs(dy)
			gradientCnts[dy] += 1
	ans = 0
	visited = set()
	for (k, v) in gradientCnts.items():
		if k not in visited:
			if type(k) == int:
				k2 = -k
			else:
				k2 = (-k[0], -k[1])
			if k2 in gradientCnts.keys():
				v2 = gradientCnts[k2]
				ans += v * v2
				visited.add(k2)
	allAns.append(ans)
multiLineArrayPrint(allAns)


import math, sys
from collections import defaultdict, Counter, deque
from bisect import bisect_left, bisect_right
INF = float('inf')
MOD = int(1000000000.0) + 7
MAX = int(1000000.0) + 1

def solve():
	n = int(input())
	slopes = {}
	direction = {}
	for i in range(n):
		(x1, y1, x2, y2) = vars()
		_gcd = gcd(abs(y2 - y1), abs(x2 - x1))
		d = ((y2 - y1) // _gcd, (x2 - x1) // _gcd)
		if d not in direction:
			direction[d] = 1
		else:
			direction[d] += 1
		if x2 - x1 != 0:
			m = (y2 - y1) / (x2 - x1)
		else:
			m = INF if y2 >= y1 else -INF
		if m in slopes:
			slopes[m] += 1
		else:
			slopes[m] = 1
	res = 0
	for k in direction:
		d = (-k[0], -k[1])
		if d in direction:
			res += direction[d] * direction[k]
	ans = res // 2
	print(ans)

def main():
	t = 1
	t = int(input())
	for _ in range(t):
		solve()

def gcd(a, b):
	while b:
		(a, b) = (b, a % b)
	return a

def input():
	return sys.stdin.readline().rstrip('\n').strip()

def print(*args, sep=' ', end='\n'):
	first = True
	for arg in args:
		if not first:
			sys.stdout.write(sep)
		sys.stdout.write(str(arg))
		first = False
	sys.stdout.write(end)
primes = [1 for i in range(MAX)]

def sieve():
	global primes
	primes[0] = primes[1] = 0
	i = 2
	while i <= MAX ** 0.5:
		j = i * i
		while primes[i] and j < MAX:
			if j % i == 0:
				primes[j] = 0
			j += i
		i += 1

def vars():
	return map(int, input().split())

def array():
	return list(vars())
main()


import sys
from collections import Counter
r = sys.stdin.readline

def gcd(a, b):
	while b:
		(a, b) = (b, a % b)
	return a
for _ in range(int(r())):
	counter = Counter()
	ans = 0
	for _ in range(int(r())):
		(x, y, u, v) = map(int, r().split())
		(x1, x2) = (u - x, v - y)
		if x1 == 0:
			x2 = x2 // abs(x2)
		elif x2 == 0:
			x1 = x1 // abs(x1)
		else:
			g = abs(gcd(x1, x2))
			(x1, x2) = (x1 // g, x2 // g)
		counter[x1, x2] += 1
	for each in counter:
		target = (-each[0], -each[1])
		if target in counter:
			ans += counter[each] * counter[target]
	print(ans // 2)


import math
from collections import defaultdict
IP = lambda : list(map(int, input().split()))
for _ in range(int(input())):
	ret = 0
	dic = defaultdict(int)
	n = int(input())
	lst = [0] * n
	for i in range(n):
		lst[i] = IP()
	for (x, y, u, v) in lst:
		distance = ((u - x) ** 2 + (v - y) ** 2) ** 0.5
		cosx = round((u - x) / distance, 11)
		cosy = round((v - y) / distance, 11)
		ret += dic[-cosx, -cosy]
		dic[cosx, cosy] += 1
	print(ret)


t = int(input())

def gcd(a, b):
	while a != 0:
		(a, b) = (b % a, a)
	return b

def solve():
	n = int(input())
	lookup = {}
	for _ in range(n):
		(x, y, u, v) = map(int, input().split())
		x = x - u
		y = y - v
		g = gcd(abs(x), abs(y))
		(x, y) = (x // g, y // g)
		if (x, y) not in lookup:
			lookup[x, y] = 0
		lookup[x, y] += 1
	ans = 0
	s = set()
	for (x, y) in lookup:
		if (x, y) in s:
			continue
		else:
			s.add((x, y))
			if (-x, -y) in lookup:
				ans += lookup[x, y] * lookup[-x, -y]
				s.add((x, y))
				s.add((-x, -y))
	return ans
while t:
	t -= 1
	ans = solve()
	print(ans)


import os
from io import BytesIO, IOBase
import sys
from collections import defaultdict, deque, Counter
from math import sqrt, pi, ceil, log, inf, gcd, floor
from itertools import combinations, permutations
from bisect import *
from fractions import Fraction
from heapq import *
from random import randint

def main():
	for _ in range(int(input())):
		n = int(input())
		b = Counter()
		for i in range(n):
			(x, y, u, v) = map(int, input().split())
			z = gcd(v - y, u - x)
			p = (v - y) // z
			q = (u - x) // z
			if not p:
				q = q / abs(q)
			if not q:
				p = p / abs(p)
			b[p, q] += 1
		ans = 0
		c = set()
		for i in b:
			if i not in c:
				z = b[i]
				y = b[-i[0], -i[1]]
				ans += y * z
				if y:
					c.add((-i[0], -i[1]))
		print(ans)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


from collections import defaultdict

def gcd(a, b):
	if a == 0:
		return b
	return gcd(b % a, a)
t = int(input())
for _ in range(t):
	n = int(input())
	people = []
	vec_dicts = defaultdict(list)
	for x in range(n):
		(x, y, u, v) = list(map(int, input().split()))
		(v1, v2) = (u - x, v - y)
		if v1 == 0:
			v2 = 1 if v2 > 0 else -1
		elif v2 == 0:
			v1 = 1 if v1 > 0 else -1
		else:
			g = gcd(abs(v1), abs(v2))
			v1 //= g
			v2 //= g
		people.append((x, y, v1, v2))
		vec_dicts[v1, v2].append(x)
	line_ups = 0
	for (v1, v2) in vec_dicts:
		if (-v1, -v2) not in vec_dicts:
			continue
		line_ups += len(vec_dicts[v1, v2]) * len(vec_dicts[-v1, -v2])
	print(line_ups // 2)