TopCoder

User's AC Ratio

NaN% (0/0)

Submission's AC Ratio

NaN% (0/0)

Tags

Description


The war between the outlaw and the sheriff has never ended, after the last defeat, the sheriff has come back with his ultimate weapon: 14400yen-battle-fury-laser-gun. +4 range rife or volcanic shotgun, none of them is its rival. With one single shot, 14400yen-battle-fury-laser-gun eliminates an outlaw directly, turning the sheriff's foe into dust.


However, after an excess amount of usage, the 14400yen-battle-fury-laser-gun suffers from malfunciton: it could not shoot targets that is at its first octant, i.e. targets whose x,y,z coordinates are all larger than the sheriff's coordinate. This is definitely unacceptable however due to limited budget the sheriff would have to make do with the malfunctioned weapon.


The sheriff would like to evaluate the effect of the malfunction, though.
There are N distinct positions (given in 3-D coordinates) which are possible location for one (either the sheriff or outlaws) to occupy during a battle. (Yes, helicopters or rocket-suits are not unseen of, so 3-D coordinates are definitely necessary, blame the modern technology!) If location A(xa,ya,za) and B(xb,yb,zb) satisfies simultaneously xa<xb, ya<yb, za<zb, then due to malfunction of the gun the sheriff cannot shoot an outlaw standing at position B, such a position pair (A,B) is called a "Malfunction-Threat-Position-Pair". To estimate the possibility that he might be standing at a place where he cannot assault his foe, the sheriff would like to know among all position pairs, how many "Malfunction-Threat-Position-Pairs" are there?

Input Format

The first line of input consists of an integer T: the number of testcases.
In each of the testcase, the first line is a single integer N indicating the number of battle positions.
In the following N line, each line describes a coordinate by xi, yi, zi, respectively.
All positions are distinct. All coordinates are integer.


1 <= T <= 100

1 <= N <= 50000

|value of coordinate| <= 100000000

Output Format

For each testcase, output a single number: the number of "Malfunction-Threat-Position-Pairs"

Sample Input 1

4

1
1 1 1

5
1 1 1
2 2 2
3 3 3
4 4 4
5 5 5

5
5 5 1 
4 4 2
3 3 3
2 2 4
1 1 5

8
3 9 4
1 2 3
2 5 7
0 4 6
3 3 3
4 5 9
2 1 2
0 4 5

Sample Output 1

0
10
0
11

Hints

Problem Source

Migrated from old NTUJ.

Kelvin

Subtasks

No. Testdata Range Score

Testdata and Limits

No. Time Limit (ms) Memory Limit (VSS, KiB) Output Limit (KiB) Subtasks
0 20000 65536 200