Northwest Wind

No attempts yetTime limit1sMemory limit256 MB

Problem

A strong northwest wind is blowing. This means you can sail in any direction between east and south (including due east and due south), but you can never sail toward the north or the west.

There is a sea dotted with several small islands. Each island is a point in the coordinate plane, where increasing $y$ points north and increasing $x$ points east.

A pair of islands counts if you can sail from one of them to the other using the northwest wind. Write a program that counts the number of island pairs you can travel between with the northwest wind.

Input

The first line contains the number of test cases $T$.

The first line of each test case contains the number of islands $n$ ($1 \le n \le 75,000$). Each of the next $n$ lines contains the coordinates $x_i$ and $y_i$ of one island, separated by a space ($-10^9 \le x_i, y_i \le 10^9$). No two islands share the same coordinates.

Output

For each test case, print the number of island pairs you can travel between with the northwest wind, one per line.