#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
typedef long long int ll;
using namespace std;
using namespace __gnu_pbds;
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define mod 1000000007
ll lcm(ll a,ll b)
{
return (a*b)/__gcd(a,b);
}
ll binExp(ll a,ll b)
{
if(b==0)
return 1;
ll res=binExp(a,b/2);
if(b&1)
{
return (a*res*res)%mod;
}
else
{
return (res*res)%mod;
}
}
bool isPrime(ll n)
{
for(ll i=2; i*i<=n; i++)
{
if(n%i==0)
{
return false;
}
}
return true;
}
void solve()
{
ll n,d;
cin>>n>>d;
ll a,b;
cin>>a>>b;
ll temp=(d*a);
n-=d;
temp+=(n*b);
cout<<temp<<endl;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
ll t;
cin>>t;
// t=1;
ll caseNo=1;
while(t--)
{
// cout<<"Case "<<caseNo<<": ";
// caseNo++;
solve();
}
return 0;
}