Scientific Experiment
John wants to be a scientist. A first step of becoming a scientist is to perform experiment. John has decided to experiment with eggs. He wants to compare the hardness of eggs from different species. He has decided to use a nearby large multistoried building for this purpose. For each species he will try to find the highest floor from which he can drop the egg and it will not break. The building has (n + 1) floors numbered from 0 to n. John has a book from which he knows that
- If an egg is dropped from the topmost floor, it will surely break.
- If an egg is dropped from floor 0, it will not break.
- The eggs of same species are of same strength. That means if any egg breaks when dropped from the k-th floor; all the eggs of that species will break if dropped from k-th floor.
- If an egg is unbroken after dropping it from any floor, it remains unharmed, that means the strength of the egg remains same.
- To know the status of the dropped egg John has to go outside the building.
Unfortunately John has a few problems.
• He can only carry one egg at a time.
• He can buy eggs from a shop inside the
building and an egg costs x cents.
• To enter the building he has to pay y cents if he has no egg with him and z cents if he carries an egg with him.
• He does not want to waste any egg so he will not leave any unbroken egg on the ground. But if an egg is broken, he leaves it there.
• If he has an intact egg at the end, he can
sell it for x/2 cents. He does not need to enter the building to sell the egg.
These problems are not going to tame John’s curious mind. So he has decided to use an optimal strategy and minimize his cost in the worst case. As John is not a programmer, he has asked for your help.
Input
Input starts with a positive integer T (T ≤ 50) denoting the number of cases. Each case contains a line with 4 integer n x y z as described in the statement. You may assume that 1 < n ≤ 1000 and 1≤x,y,z≤105 andxiseven.
2/2
Output
For each test case, print the case number and the minimized worst case cost.
Explanation of Case 1: John knows that the egg will break if dropped from 4th floor, but will not break if dropped from 0th floor. An optimal solution may be
• John enters the building without any egg (¢998).
• John buys an egg (¢2)
• John drops an egg from 2nd floor. John goes out and checks the egg.
– If it breaks,
- John again enters the building without any egg (¢998) and buys an egg there ¢2. * He drops the egg from 1st floor.
· If it does not break then answer to his problem is 1 and he can sell the egg for ¢1. So his final cost in ¢1999.
· If it breaks then the answer to his problem is 0th floor and his final cost is ¢2000. – If it does not break,
- John enters the building with the egg (¢1000). * He drops it from 3rd floor.
· If it does not break then answer to his problem is 3 and he can sell the egg for ¢1. So his final cost in ¢1999.
· If it breaks then the answer to his problem is 2 and final cost is ¢2000. So, using this strategy, his worst case cost is ¢2000.
Sample Input
7
4 2 998 1000 16 2 1000 1000 16 1000 1 1
4 1000 1 1 7222
9 2 1 100
11 2 100 1
Sample Output
Case 1: 2000
Case 2: 4008
Case 3: 1015
Case 4: 1003
Case 5: 10
Case 6: 24
Case 7: 111