Compo
InterviewTime limit1sMemory limit256 MB
Count the pairs of contests whose inclusive time ranges overlap in each test case.
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 to time , 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 other contests costs its manager 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 , the number of test cases ().
The first line of each test case contains a single integer , the number of contests (). Each of the next lines contains two integers and separated by a space, the start and end times of that contest ().
Output
For each test case, print one line in the form Case n: R, where is the test case number starting from 1 and is the number of fights in that test case.
can exceed the range of a 32-bit integer.