/*Rabbi Zidni Eilmaa*/
// We are open. We are looking for SHOTRUJ...
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef string str;
typedef vector<ll> vll;
typedef vector<pair<ll, ll>> vpl;
typedef set<ll> sll;
typedef map<ll,ll> mll;
typedef pair<int,int> pint;
typedef pair<ll,ll> pll;
double pi = acos(-1.0);
#define debug(x) cout<<#x<<" "<<x<<endl;
#define loop for(int i=1; i<=n; i++)
#define all(a) (a).begin(), (a).end()
#define min3(a,b,c) min(a,min(b,c))
#define max3(a,b,c) max(a,max(b,c))
#define min4(a,b,c,d) min(a,min(b,min(c,d)))
#define max4(a,b,c,d) max(a,max(b,max(c,d)))
#define forn(i, n) for(int i=1; i<=(int)n; i++)
#define ANS cout << ans << "\n"
#define PY cout << "YES\n"
#define PN cout << "NO\n"
int mod = 1e9 + 7;
void init(){
}
void solve()
{
ll n, d, a, b;
cin >> n >> d >> a >> b;
ll p = min(n, d), q = max(0LL, n-d);
cout << p * a + q * b << '\n';
return;
}
int32_t main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
init();
int t = 1;
cin >> t;
for(int i=1; i<=t; i++){
// cout << "Case " << i << ": ";
solve();
}
return 0;
}