#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define int ll
#define double long double
const int N = 2e5 + 15, MOD = 1e9 + 7;
#define deb(x) cout << #x << "=" << x << endl;
#define F first
#define S second
void solve() {
    int n, d, a, b;
    cin >> n >> d >> a >> b;
    if (n <= d) {
        cout << (n * (a));
        return;
    }
    cout << ((d * a) + ((n - d) * b));
}
signed main() {
    ios_base::sync_with_stdio(false);
    cout.tie(NULL);
    cin.tie(NULL);
    int tt = 1;
    cin >> tt;
    for (int i = 0; i < tt; i++) {
        // cout << "Case " << i + 1 << ": ";
        solve();
        cout << "\n";
    }
}