#include using namespace std; typedef long long ll; typedef string str; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); ll t; cin >> t; cout << fixed << setprecision(0); while (t--) { ll l, r, a, b; cin >> l >> r >> a >> b; cout << max(l * a + b, r * a + b) << "\n"; } return 0; }