Under construction

Still being built. Things may change

Compo

Interview

Time limit1sMemory limit256 MB

Summary
Count the pairs of contests whose inclusive time ranges overlap in each test case.
Level

Easy3 of 10

Topics
Sorting, Intervals
Solved
No attempts yet

Problem

Ahmed is the head of systems for a collegiate programming contest. Back in college he predicted the output of programs without compiling or running them, so his colleagues started calling him Compo, short for compiler.

Ahmed is often asked to help organize contests, and he almost always agrees. The catch is that if he takes a contest that runs from time ClC_l to time CrC_r, he has to stay there from the start of the contest until it ends.

Sometimes two or more contests overlap. When one contest starts before another one finishes, Ahmed can attend only one of them, and the contest managers fight over who gets his help.

The managers of two overlapping contests fight each other once. So a contest that overlaps MM other contests costs its manager MM fights, and the total number of fights equals the number of pairs of contests whose time ranges overlap. Two contests also count as overlapping when one ends at exactly the time the other starts, because Ahmed is not that fast.

You are given the number of contests and the start and end times of each one. Count the number of fights.

Input

The first line contains a single integer TT, the number of test cases (1≤T≤1001 \le T \le 100).

The first line of each test case contains a single integer NN, the number of contests (1≤N≤1051 \le N \le 10^5). Each of the next NN lines contains two integers ClC_l and CrC_r separated by a space, the start and end times of that contest (1≤Cl≤Cr≤1091 \le C_l \le C_r \le 10^9).

Output

For each test case, print one line in the form Case n: R, where nn is the test case number starting from 1 and RR is the number of fights in that test case.

RR can exceed the range of a 32-bit integer.

Examples2

  1. Example 1

    Input
    1
    3
    1 5
    1 2
    2 4
    
    Expected output
    Case 1: 3
    
  2. Example 2

    Input
    3
    1
    5 5
    2
    1 2
    2 3
    3
    1 2
    3 4
    5 6
    
    Expected output
    Case 1: 0
    Case 2: 1
    Case 3: 0