P9627 [ICPC 2020 Nanjing R] Fireworks

Description

Kotori is practicing making fireworks for the upcoming hanabi taikai$^1$. It takes her $n$ minutes to make a single firework, and since she is not very skilled at making fireworks, each firework has only a probability of $p \times 10^{-4}$ of being perfect. After she finishes making a firework, she can either start making the next firework right away, or spend $m$ minutes to light all the remaining fireworks she has already finished. If there is at least one perfect firework among the fireworks she lights, she will be happy and go to rest. Otherwise, she will continue practicing. Please find the minimum expected practicing time before she goes to rest if she uses the best strategy. Note that no matter how many fireworks remain, it always takes $m$ minutes to light them all. $^1$ Hanabi taikai: Romaji of the Japanese word ``花火大會``, which means the firework... err... party?

Input Format

There are multiple test cases. The first line of the input contains an integer $T$ ($1 \le T \le 10^4$), indicating the number of test cases. For each test case: The only line contains three integers $n$, $m$, and $p$ ($1 \le n, m \le 10^9$, $1 \le p \le 10^4$).

Output Format

For each test case, output one line with one number, indicating the minimum expected practicing time. Your answer will be considered correct if and only if the absolute or relative error does not exceed $10^{-4}$.

Explanation/Hint

Translated by ChatGPT 5