Load Testing (Small)

For each case, compute the fewest adaptive load tests that guarantee bracketing the capacity within a factor of C in the worst case.

Medium7Dynamic programmingBinary searchNo attempts yetTime limit5sMemory limit512 MB

Problem

Next year's programming contest site expects PP participants at once, and you have to confirm in advance that the site survives that load.

During last year's contest you learned that the site handles at least LL people at a time without any errors. You also know that the site cannot handle PP people yet.

To decide how many more machines you need, you want to know within a factor of CC how many people the site supports. That means finding an integer aa for which you know the site supports aa people and you know the site does not support a×Ca \times C people.

You can run a series of load tests. One load test picks an integer XX of your choice and tells you whether the site supports at least XX people. You may choose each test after seeing the results of the previous ones.

With an optimal strategy, how many load tests do you need in the worst case?

Input

The first line contains the number of test cases TT.

Each of the next TT lines contains the integers LL, PP and CC in that order, separated by spaces.

Limits

  • 1T10001 \le T \le 1000
  • 1L<P10001 \le L < P \le 1000
  • 2C102 \le C \le 10
  • LL, PP and CC are all integers.

Output

For each test case, print one line in the form Case #x: y. Here xx is the case number starting from 1, and yy is the number of load tests you need in the worst case before you know within a factor of CC how many people the site supports.

Hint

For L=19L = 19, P=57P = 57, C=3C = 3 you already know that the site supports 19 people and does not support 57. Those two values are exactly a factor of 3 apart, so no test is needed.

For L=24L = 24, P=97P = 97, C=2C = 2 you could test 48 first. If the site supports 48 people, more testing is needed because 48×2<9748 \times 2 < 97. You could test 49 instead. If the site does not support 49 people, more testing is needed because 24×2<4924 \times 2 < 49. Either way the worst case takes two tests.