11650 - Rectangle   

Description

There are N points on the Cartesian coordinate system. Now we have to find how many rectangles we can draw with those N points. Notice that we only need to find the rectangles whose 4 edges are parallel with the X and Y axes.

 

For example, we can draw 3 rectangles in the following figure.

Input

The first line is the number T (1<=T<=15), meaning that there are T times of operation.
The second line is N, meaning that there are N points for every operation.
For the next N lines, each line contains two numbers, x and y, meaning that the position of the point is (x, y). Besides, there won't be two points on the same position.

 

Output

For every operation, please output the max number of rectangles we can draw.

 

### Hint1:

Implement two loops to find the left-top and the right-bottom points of each possible rectangle, and use these two points for judging.

 

### Hint2:

  • In test case 1, N<=4, -1000000000 <= x, y <= 1000000000.
  • In test case 2, N<=100, -1000000000 <= x, y <= 1000000000.
  • In test case 3, N<=300, -1000000000 <= x, y <= 1000000000.
  • In test case 4, N=2000, -100000 <= x, y <= 100000, all the points are only on two lines parallel to y-axis.
  • In test case 5, N<=500, -1000000000 <= x, y <= 1000000000.

Sample Input  Download

Sample Output  Download

Tags




Discuss