Question
Glow Budget
Alice is designing a serene study corner and needs exactly N lamps. She prefers the vibrant shine of red lamps but finds blue lamps more affordable. To achieve her desired ambiance, at least K lamps must be red. With red lamps costing X rupees each and blue lamps Y rupees each, find the minimum cost for Alice’s ideal setup.
Input
The first line of input will contain a single integer T, denoting the number of test cases.
Each test case consists of a single line containing four space-separated integers N, K, X, Y.
Constraints
1 ≤ T ≤ 103
1 ≤ N ≤ 108
0 ≤ K ≤ N
1 ≤ X, Y ≤ 10
Each test case consists of a single line containing four space-separated integers N, K, X, Y.
Constraints
1 ≤ T ≤ 103
1 ≤ N ≤ 108
0 ≤ K ≤ N
1 ≤ X, Y ≤ 10
Output
For each test case, output on a new line the minimum amount of money Alice needs to pay in order to buy N lamps such that at least K of the lamps bought are red.
Example
Sample Input
4
2 2 5 1
4 1 3 1
3 0 4 7
5 2 3 4
Sample Output
10
6
12
15
Explanation
Alice buys 2 red lamps with 2 x 5 = 10 rupees.
Alice buys 1 red lamp and 3 blue lamps with 1 x 3 + 3 x 1 = 6 rupees.
Alice buys 3 red lamps with 3 x 4 = 12 rupees.
4
2 2 5 1
4 1 3 1
3 0 4 7
5 2 3 4
Sample Output
10
6
12
15
Explanation
Alice buys 2 red lamps with 2 x 5 = 10 rupees.
Alice buys 1 red lamp and 3 blue lamps with 1 x 3 + 3 x 1 = 6 rupees.
Alice buys 3 red lamps with 3 x 4 = 12 rupees.