#include using namespace std; typedef long long ll; typedef unsigned long long ull; int main(void) { ios_base::sync_with_stdio(false); int tests; cin >> tests; for (int i = 0; i < tests; i++) { ull myH, liftH, mySpeed, liftSpeed; cin >> myH >> liftH >> mySpeed >> liftSpeed; if(myH < liftH) { cout << min(myH * mySpeed, liftH * liftSpeed) << endl; } else { // first of all, call lift here cout << min(myH * mySpeed, (myH - liftH) * liftSpeed + myH * liftSpeed ) << endl; } } return 0; }