Now comes the real problem. You need to buy $n$ chocolates.
You can buy $2$ types of chocolates. Each type has a infinite amount of chocolates.
The first type chocolate has an initial price $p$, where the second type chocolate has an initial price $q$.
Each time one buys a chocolate of the first type, the price of this type gets decreased by $x$. Similarly, each time a second type chocolate is bought, the price of this type gets decreased by $y$.
Say $p = 9$ and $x = 3$ for the first type of chocolate. Currently the price is $9$. After buying one chocolate the price decreases by $3$ and now the new price is $6$. After buying another chocolate the price will again decrease by $3$ and the new price will be $3$.
You have to find the minimum cost to buy $n$ 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 $t$ denoting the number of test cases.
The next line of each test case contains 5 space separated integers.
$n$- The amount of chocolates to be bought.
$p$- The initial price of first type chocolate
$q$- The initial price of second type chocolate
$x$- The amount of price reduces after buying each chocolate of first type
$y$- The amount of price reduces after buying each chocolate of second type
$1 \le t \le 10^5$
$1 \le n \le 10^6$
$1 \le x\le p \le 10 ^ 7$
$1\le y\le q\le 10 ^ 7$
The output should contain $t$ lines. $i$th line of output should contain the minimum cost for $i$th test case.
Input | Output |
---|---|
1 5 100 50 5 3 | 220 |