Now comes the real problem. You need to buy chocolates.
You can buy types of chocolates. Each type has a infinite amount of chocolates.
The first type chocolate has an initial price , where the second type chocolate has an initial price .
Each time one buys a chocolate of the first type, the price of this type gets decreased by . Similarly, each time a second type chocolate is bought, the price of this type gets decreased by .
Say and for the first type of chocolate. Currently the price is . After buying one chocolate the price decreases by and now the new price is . After buying another chocolate the price will again decrease by and the new price will be .
You have to find the minimum cost to buy chocolates and make Chimatu happy!!!
[Note: It is guaranteed that the price of any chocolate will never be negative]
The first line of the input contains an integer denoting the number of test cases.
The next line of each test case contains 5 space separated integers.
- The amount of chocolates to be bought.
- The initial price of first type chocolate
- The initial price of second type chocolate
- The amount of price reduces after buying each chocolate of first type
- The amount of price reduces after buying each chocolate of second type
The output should contain lines. th line of output should contain the minimum cost for th test case.
Input | Output |
---|---|
1 5 100 50 5 3 | 220 |