Picu Bank
26% Success31232 Attempts20 Points1s Time Limit256MB Memory1024 KB Max Code

You have $$D$$ dollars with you. You want to put it into a Bank, namely Picu Bank. This bank has a peculiar behavior for interest. Regardless of the Bank deposit amount, every month it adds $$A$$ dollars to your bank account and this continues till $$M$$ months. Exaxtly on $$ M+1 $$ months, it adds $$B$$ dollars $$ (B < A) $$ to your bank account. This scanario repeats again in same manner.( i.e on the $$ (M+2)^{th}$$ month $$A$$ dollars are added, and so on.. ). Your task is to find out how many months does it take for the dollar amount to reach at least $$X$$, in the bank account .    

Input:

Input starts with an integer $$ T (1 \le T \le 100000) $$, denoting the number of test cases.  Each case starts with 5 integers $$D, A, M, B$$ , and $$ X $$ as described in problem statement.

 

Constraints:

  • $$ 1 \le D,M,X \le 10^9 $$
  • $$ 1 \le B < A \le 10^9 $$ 

Output:

For each case of input minimum number of months needed to reach dollar value of at least X in a single line.

Note that the Expected Output feature of Custom Invocation is not supported for this contest. 

Examples
Input
2
2 5 4 3 51
2 5 4 3 46
Output
11
10
Explanation

 

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading Editor...
Results