Please note the unusual memory limit.
You are given $$$n$$$ distinct points $$$P_1,P_2,\ldots,P_n$$$ on a plane. The distance $$$\text{dist}(p_1,p_2)$$$ between two points $$$p_1=(x_1,y_1)$$$ and $$$p_2=(x_2,y_2)$$$ is defined as the Manhattan distance $$$|x_1-x_2|+|y_1-y_2|$$$.
Three points $$$p_i=(x_i,y_i)$$$, $$$p_j=(x_j,y_j)$$$, $$$p_k=(x_k,y_k)$$$ are said to form a Manhattan Triangle in Square if the following conditions hold.
An example of three points forming a Manhattan Triangle in Square. Given the coordinates of the points, please count the triples $$$(i,j,k)$$$ that satisfy the following conditions.
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 100$$$). The description of the test cases follows.
The first line of each test case contains a single integer $$$n$$$ — the number of points ($$$1 \le n \le 20\,000$$$).
Each of the following $$$n$$$ lines contains two integers $$$x_i$$$ and $$$y_i$$$ denoting the point $$$P_i$$$ ($$$-10^7 \le x_i,y_i \le 10^7$$$).
It is guaranteed that the given points are pairwise distinct.
It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$20\,000$$$.
For each test case, output the number of triples that satisfy the given conditions on a separate line.
230 06 22 6200 00 10 20 30 41 11 21 31 41 52 02 12 22 32 43 13 23 33 43 5
1 8
The first test case has one triple forming a Manhattan Triangle in Square, identical to the one given in the diagram above.
It can be shown that the second test case has exactly $$$8$$$ triples forming a Manhattan Triangle in Square.