/**
* author: pollob18
* created: July 2024
**/
#include <bits/stdc++.h>
#define ll long long int
#define yes "YES"
#define no "NO"
#define nl "\n"
#define pb push_back
#define all(a) a.begin(),a.end()
#define allr(a) a.rbegin(),a.rend()
#define Code_By_pollob ios::sync_with_stdio(false); cin.tie(0);
using namespace std;
void solution()
{
ll n,d;
cin>>n>>d;
ll a,b;
cin>>a>>b;
ll x=d*a;
ll y=(n-d)*b;
cout<<x+y<<nl;
}
int main()
{
Code_By_pollob
int tc;
cin>>tc;
while(tc--)
{
solution();
}
return 0;
}