#include <iostream>
using namespace std;
int main() {
int t, n, d, a, b;
cin >> t; // Read the number of test cases
for (int i = 0; i < t; i++) {
cin >> n >> d; // Read the number of nights and the number of first nights with higher rate
cin >> a >> b; // Read the cost per night for first D nights and subsequent nights
// Calculate the cost for the first D nights or for all N nights if N <= D
int firstPart = min(n, d) * a;
// Calculate the cost for the remaining nights if N > D
int secondPart = max(n - d, 0) * b;
// Total cost is the sum of the above two parts
int totalCost = firstPart + secondPart;
cout << totalCost << endl; // Output the total cost for this test case
}
return 0;
}