/*
* @author:- SYEDA SADIATUL JANNAT TUSHI
* date & time :2024-09-05 20:55:29
* BANGLADESH , SYLHET.
*/
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define rep(i, a, b) for(int i = (a); i < (b); i++)
#define ll long long
#define vi vector<ll>
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
void solve() {
ll n,d,a,b;
cin>>n>>d>>a>>b;
ll ek=(d*a);
ll dui=(n-d)*b;
ll ans=ek+dui;
if(n<=d){
cout<<n*a<<endl;
}
else{
cout<<ans<<endl;
}
}
int main() {
fast;
ll T;
cin >> T;
while (T--) {
solve();
}
return 0;
}