Problems
To welcome attendees to a developers' conference on Jupiter's moon of Io, the organizers inflated
many giant beach balls. Each ball is in roughly the shape of either a
The conference was held on an infinite horizontal line, with station
BALL-E has two storage compartments, each of which can hold a single beach ball. One compartment
can only hold
BALL-E initially has both the
- Move left one station or right one station. This costs 1 unit of power.
- If there is a ball at the current station, and BALL-E is not already storing a ball of that shape, it can put the ball in the appropriate compartment. This takes 0 units of power.
- If there is a ball at the current station, BALL-E can compress it so that its shape becomes
the other shape. That is, a
1 -shaped ball becomes a0 -shaped ball, or vice versa. It takes\mathbf{C} units of power to do this. Note that BALL-E may not change the shape of a ball that it has already put into one of its compartments. - If BALL-E is at station 0 and is storing at least one ball, it can deposit all balls from its compartment(s) into the beach ball storage warehouse. This takes 0 units of power and leaves both compartments empty.
Notice that if BALL-E moves to a station and there is a ball there, BALL-E is not required to pick it up immediately, even if the robot has an open compartment for it. Also, if BALL-E moves to the station with the warehouse, it is not required to deposit any balls it has.
Find the minimum number of units of power needed for BALL-E to transfer all of the balls to the warehouse, using only the moves described above.
Input
The first line of the input gives the number of test cases,
The first line of each test case contains two integers,
The next
Output
For each test case, output one line containing Case #,
where
Example
4
5 0
3 0
6 0
8 0
10 1
15 1
5 10
3 0
6 0
8 0
10 1
15 1
5 1
3 0
6 0
8 0
10 1
15 1
2 0
1000000000 0
-1000000000 1
Case #1: 52
Case #2: 56
Case #3: 54
Case #4: 4000000000