#include <iostream>
using namespace std;
// Function to calculate the total accommodation fee for each test case
int calculate_fee(int N, int D, int A, int B) {
if (N <= D) {
return N * A;
} else {
return D * A + (N - D) * B;
}
}
int main() {
int T;
// Input the number of test cases
cin >> T;
// Process each test case
for (int i = 0; i < T; i++) {
int N, D, A, B;
// Input N (total nights) and D (discount nights)
cin >> N >> D;
// Input A (higher rate) and B (lower rate)
cin >> A >> B;
// Output the total accommodation fee for this test case
cout << calculate_fee(N, D, A, B) << endl;
}
return 0;
}