include <bits/stdc++.h>
using namespace std;
define ll long long
int main()
{
int t;
cin>>t;
while(t–)
{
ll n,m;
cin>>n>>m;
ll a,b;
cin>>a>>b;
cout<<nm - min(am,b*n)<<endl;
}
}
// below is the problem link (Save people of starters 106 , div 3 problem D)
// FIZZBUZZ2306 Problem - CodeChef