N trees were planted on a side of a long straight road. On the other side, there are farms, industries etc. The market price of these trees is huge now. Some greedy people want to cut these trees down and want to be millionaires. They lobbied their way through the Govt. decoying that they would develop the area. You published this conspiracy in the web and millions raised their voices against this.
You gathered the information of the trees and found the type and height of all trees. For simplicity, you represented them as integers. You want to find the overall price of the trees. To find the price, the following method is used:
- The trees are first partitioned into groups with the condition that, types of two trees will not be similar in a group. A group can only be formed using contiguous trees.
- The price of a group is equal to the height of the tallest tree.
- The overall price is the summation of prices of all groups.
Input
Input starts with an integer T (≤ 5), denoting the number of test cases.
Each case starts with an integer N (1 ≤ N ≤ 2*105). Each of the next N lines contains two integers typei heighti (1 ≤ typei, heighti ≤ 2*105) of the ith tree from left to right.
Output
For each case, print the case number and the minimum possible price of the trees according to the scheme described above.
Sample
Sample Input | Sample Output |
---|---|
2 5 3 11 2 13 1 12 2 9 3 13 4 3 5 2 21 3 12 2 5 | Case 1: 26 Case 2: 31 |
Notes
Dataset is huge, use faster I/O methods.