| "I am invincible, invincible. You're ... Owww!" |
Adrian likes solving programming problems. There is a new problem archive website that has opened recently, and Adrian wants to climb to the number one spot in the ranklist. The ranklist contains every registered user, sorted by the number of problems solved. When there are two people who have solved the same number of problems, the one who has reached that number the earliest appears higher in the ranklist.
To reach the number 1 spot, Adrian's plan is to solve enough problems to move up by one spot in the ranklist every day. Sometimes, it is impossible to move by only one spot. In those cases, he will move up as few spots as possible. How many days will Adrian need to reach the top spot, assuming no one else solves any problems?
Input
The first line of input gives the number of cases, N.
N test cases follow. Each one starts with a line containing
n (0<n<=10000) - the number of registered users.
The next n lines will each contain information about one user -
the user ID, the number of problems solved and the submission ID of
the last solved problem. Adrian's user ID is 1000 and he has at least
one solved problem. All submission ID's will be unique; higher submission
ID's correspond to later times.
Output
For each test case, output one line containing "Case #x:"
followed by the number of days until Adrian is number 1.
| Sample Input | Sample Output |
4 2 1000 9 234 1001 10 555 1 1000 8 23462 4 1000 10 234 1001 10 141 1002 10 444 1005 10 100 5 1000 10 99 1001 0 -1 1002 11 998 1003 11 997 1004 12 8 |
Case #1: 1 Case #2: 0 Case #3: 1 Case #4: 2 |