Under construction

Still being built. Things may change

Allergy Testing (Large)

Time limit90sMemory limit512 MB

Summary
Find the shortest worst-case schedule of pooled food tests with asymmetric wait times that identifies the single allergen.
Level

Medium7 of 10

Topics
Dynamic programming, Binary search, Math
Solved
No attempts yet

Problem

Kelly is allergic to exactly one of NN foods, but she does not know which one, so she runs experiments to find out.

In one experiment Kelly picks a set of foods and eats all of them. Exactly AA days later she learns whether she reacted. If she did not react, she is not allergic to any food in that set. If she did react, the food she is allergic to is one of the foods in that set, and the reaction takes BB days to fade, counted from the moment she ate.

Kelly starts an experiment only after the previous one is completely over, so an experiment that causes no reaction occupies AA days and an experiment that causes a reaction occupies BB days. She picks the foods for each experiment after seeing the results of all earlier experiments.

The answer is the number of days until Kelly knows which food she is allergic to. Because a result arrives AA days after she eats, she never has to wait for the reaction of her last experiment to fade.

Kelly plays so that the worst case is as short as possible. How many days does she need in the worst case?

Input

The first line contains the number of test cases TT. Each of the next TT lines contains three space separated integers NN, AA and BB.

Constraints

  • 1≤T≤2001 \le T \le 200
  • 1≤N≤10151 \le N \le 10^{15}
  • 1≤A≤B≤10121 \le A \le B \le 10^{12}

Output

For each test case, print one line containing Case #x: y, where xx is the test case number starting from 1 and yy is the number of days Kelly needs in the worst case to find out which food she is allergic to.

Hint

For N=4N = 4, A=5A = 5 and B=7B = 7 the answer is 12.

  • Kelly first eats foods 1 and 2.
  • If there is no reaction after 5 days, she eats food 3. Five days after that she knows whether she is allergic to food 3 or food 4, so this branch ends on day 10.
  • If the first experiment does cause a reaction, she eats food 1 seven days after the first experiment started. Five days after that she knows whether it is food 1 or food 2, so this branch ends on day 12.

Examples3

  1. Example 1

    Input
    3
    4 5 7
    8 1 1
    1 23 32
    
    Expected output
    Case #1: 12
    Case #2: 3
    Case #3: 0
    
  2. Example 2

    Input
    1
    1 1 1
    
    Expected output
    Case #1: 0
    
  3. Example 3

    Input
    6
    2 1 1
    3 1 1
    4 1 1
    1023 1 1
    1024 1 1
    1025 1 1
    
    Expected output
    Case #1: 1
    Case #2: 2
    Case #3: 2
    Case #4: 10
    Case #5: 10
    Case #6: 11