Question
The Paints
In a lively art supply store, a talented artist named "Leo" was on a mission to purchase some vibrant paints for his latest masterpiece. The shop offered two types of paints: ruby red and sapphire blue. A jar of ruby red paint cost X rupees, while a jar of sapphire blue paint was priced at Y rupees.
Leo planned to buy exactly N jars of paint, but he had a specific requirement: he wanted at least K jars to be ruby red. With a tight budget Leo aimed to calculate the least amount of money he would need to spend to fulfill his artistic vision. Can you help Leo figure out the best way to make his purchase?
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
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 least amount of money Leo needs to pay in order to buy N jars of paint such that at least K of the jars 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
Test case 1: Leo buys 2 red jars with 2 ⋅ 5 = 10 rupees.
Test case 2: Leo buys 1 red jar and 3 jars with 1. 3 + 3 . 1 = 6 rupees.
Test case 3: Leo buys 3 red jars with 3 ⋅ 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
Test case 1: Leo buys 2 red jars with 2 ⋅ 5 = 10 rupees.
Test case 2: Leo buys 1 red jar and 3 jars with 1. 3 + 3 . 1 = 6 rupees.
Test case 3: Leo buys 3 red jars with 3 ⋅ 4 = 12 rupees.