#include using namespace std; using ll = long long; #define fi first #define se second int main(){ int t; cin >> t; for(int i = 0; i < t; ++i){ int l, r, a, b; cin >> l >> r >> a >> b; cout << max(a * l + b, a * r + b) << endl; } return 0; }