#include <bits/stdc++.h>
using namespace std;
#define int long long int
void solve() {
int n, d;
cin >> n >> d;
int a, b;
cin >> a >> b;
// Check if nights spent is less than or equal to the first D nights
if (n <= d) {
cout << n * a << endl; // All nights are charged at the rate 'a'
} else {
cout << (d * a) + (n - d) * b << endl; // First D nights at 'a', rest at 'b'
}
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int test;
cin >> test;
for (int tc = 0; tc < test; ++tc) {
solve();
}
return 0;
}