The lines at the air pump at your gas station are getting too long! You want to optimize the process to help customers more quickly inflate their tires, sports balls, giant parade balloon animals, and other products.
The pump is automatic: you set the pressure to a specific number of pascals and plug the pump into the inflatable product, and it will inflate as needed to that exact pressure. There are only two buttons on the pump: up and down. They increase and decrease the target pressure, respectively, by exactly

There is a line of
The pump is initially set to
Input Specification
The first line of the input gives the number of test cases,
Output Specification
For each test case, output one line containing Case #x: y
, where
Limits
Time limit: 5 seconds.
Memory limit: 1 GB.
Test Set 1
Test Set 2
Sample Input
2
3 3
30 10 40
20 50 60
60 60 50
5 2
1 1000000000
500000000 1000000000
1 1000000000
500000000 1
1 1000000000
Sample Output
Case #1: 110
Case #2: 4999999996
In Sample Case #1, an optimal way to use the pump is:
- press up
times, setting the pump to ; pump the product (from customer 1) that needs pascals, - press up
times, setting the pump to ; pump the product (from customer 1) that needs pascals, - press down
times, setting the pump to ; pump the product (from customer 1) that needs pascals, - press down
times, setting the pump to ; pump the product (from customer 2) that needs pascals, - press up
times, setting the pump to ; pump the product (from customer 2) that needs pascals, - press up
times, setting the pump to ; pump the product (from customer 2) and the two products (from customer 3) that need pascals, and finally - press down
times, setting the pump to ; pump the product (from customer 3) that needs pascals.
This is a total of
In Sample Case #2, notice that the answer can be larger than
Comments