Rope Intranet

Count wire pairs that cross by sorting on one endpoint height and counting inverted pairs on the other.

Easy3SortingBrute forceInterviewNo attempts yetTime limit5sMemory limit512 MB

Problem

A company occupies two very tall buildings. The intranet that links them is made of wires, and each wire connects one window of the left building to one window of the right building.

You are looking at the buildings from the side. The windows of the left building appear as points on its right wall, and the windows of the right building appear as points on its left wall. Each wire is a straight segment between a point on the left wall and a point on the right wall.

No two wires share a window, so at most one wire leaves each window. From your viewpoint some wires cross midway, and exactly two wires meet at every crossing point. In the picture above the crossing points are the black circles and the windows are the white circles.

Count the crossing points you see.

Input

The first line contains the number of test cases TT. The first line of each test case contains NN, the number of wires. Each of the next NN lines contains two integers AiA_i and BiB_i describing one wire. AiA_i is the height of the window on the left building and BiB_i is the height of the window on the right building.

Limits

  • 1T151 \le T \le 15
  • 1N10001 \le N \le 1000
  • 1Ai1041 \le A_i \le 10^4
  • 1Bi1041 \le B_i \le 10^4
  • Within one test case, all AiA_i are different.
  • Within one test case, all BiB_i are different.
  • No three wires meet at the same point.

Output

For each test case, print one line in the form Case #x: y, where x is the test case number starting from 1 and y is the number of crossing points you see.