Millionaire (Large)

Bet any fraction of your money over M rounds with win probability P; maximize the chance of holding $1,000,000 at the end.

Hard8Dynamic programmingProbabilityNo attempts yetTime limit20sMemory limit512 MB

Problem

You have been invited onto the popular TV show "Would you like to be a millionaire?". Of course you would.

The rules are simple.

  • Before the game starts, the host spins a wheel of fortune to fix PP, the probability of winning a single bet.
  • You start with XX dollars.
  • There are MM rounds of betting. In each round you may bet any part of the money you currently hold, including none of it and all of it. The amount does not have to be a whole number of dollars or cents.
  • If you win the bet, your money grows by the amount you bet. If you lose, your money shrinks by the amount you bet.
  • After all MM rounds are over you keep your money only if you hold $1000000 or more, and the amount is then rounded down to whole dollars. If you hold less than $1000000 you get nothing.

You are given MM, PP and XX. Compute the probability of ending up with $1000000 or more when you follow the strategy that maximizes your chance of becoming a millionaire.

Input

The first line contains the number of test cases NN.

Each of the next NN lines holds one test case in the format M P X.

  • MM is an integer, the number of betting rounds.
  • PP is a real number, the probability of winning one round.
  • XX is an integer, the amount of money you start with.

Limits

  • 1N1001 \le N \le 100
  • 0P1.00 \le P \le 1.0, with at most six digits after the decimal point.
  • 1X10000001 \le X \le 1000000
  • 1M151 \le M \le 15

Output

For each test case print one line in the format Case #c: y.

  • cc is the test case number, starting at 1.
  • yy is the probability of becoming a millionaire, between 00 and 11. Print it with exactly six digits after the decimal point.

Hint

In the first sample the only way to reach $1000000 is to bet everything on the single round.

In the second sample there is a strategy that still reaches $1000000 after one lost bet. One such strategy is this.

  • You hold $600000 in the first round. Bet $150000.
  • If you lose the first round you have $450000 left. Bet $100000.
  • If you lose the first round and win the second one, you have $550000 left. Bet $450000.
  • If you win the first round you have $750000 left. Bet $250000.
  • If you win the first round and lose the second one, you have $500000 left. Bet $500000.