#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) { if (myH * mySpeed < liftH * liftSpeed) { cout << myH * mySpeed << endl; } else { cout << liftH * liftSpeed << endl; } // cout << min(myH * mySpeed, liftH * liftSpeed) << endl; } else { // first of all, call lift here if (myH * mySpeed < (2 * myH - liftH) * liftSpeed) { cout << myH * mySpeed << endl; } else { cout << (2 * myH - liftH) * liftSpeed << endl; } // cout << min(myH * mySpeed, (myH - liftH) * liftSpeed + myH * liftSpeed ) << endl; } } return 0; }