This page is still under construction.

Parts of this page are still being built. What you see may change.

Bulletproof Glass Testing Budget

Interview

Time limit1sMemory limit256 MB

Summary
Compute the minimum worst-case budget to find the exact breaking distance when each bullet and each broken pane costs money.
Level

Medium6 of 10

Topics
Dynamic programming
Solved
No attempts yet

Problem

Your boss thinks his life is in danger, so he had bulletproof glass fitted to his car. He doubts that the glass is really bulletproof. He fired one shot from FF feet away and the glass held, but he does not know whether it holds at a shorter range.

The glass has an unknown limit DD. A bullet fired from DD feet or farther cannot break it, and a bullet fired from closer than DD feet breaks it. The shot from FF feet did not break the glass, so 0≤D≤F0 \le D \le F. This DD is the value your boss wants.

Testing happens at whole feet only. One bullet costs BB. When a shot breaks the glass, replacing that pane costs another GG, and the replacement costs the same even if no further shot is needed. A pane that survives a shot is shot at again as it is.

Firing from F−1F-1 feet down to 00 feet one foot at a time settles DD and breaks at most one pane, so it costs at most F×B+GF \times B + G. Breaking more glass to save bullets is sometimes cheaper.

The testing has to determine DD whatever position the glass breaks at. Find the smallest budget that covers the worst case.

Input

The first line has the number of test configurations NN (1≤N≤1001 \le N \le 100).

Each of the next NN lines has three integers FF, GG and BB separated by spaces. FF is the distance at which the glass is known to hold (1≤F≤10001 \le F \le 1000), GG is the price of one pane of glass (1≤G≤10001 \le G \le 1000), and BB is the price of one bullet (1≤B≤1001 \le B \le 100).

Output

For each test configuration print Case #n: first, then the smallest budget needed for the testing of that configuration. Here nn is the number of the configuration, counted from 11 in input order.

Examples2

  1. Example 1

    Input
    4
    100 100 1
    100 10 10
    100 80 10
    750 90 25
    
    Expected output
    Case #1: 200
    Case #2: 110
    Case #3: 290
    Case #4: 625
    
  2. Example 2

    Input
    3
    1 1 1
    1 1000 100
    2 5 3
    
    Expected output
    Case #1: 2
    Case #2: 1100
    Case #3: 11