#include //#include // AtCoder using namespace std; //using namespace atcoder; // AtCoder using uint = unsigned int; using ll = long long; using ull = unsigned long long; using ld = long double; //using mint = modint998244353; // AtCoder using vll = vector; using vvll = vector>; using vvvll = vector>>; using vvvvll = vector>>>; using dll = deque; using ddll = deque>; using dddll = deque>>; using ddddll = deque>>>; using pll = pair; using vpll = vector>; using vvpll = vector>>; #define overload2(_1, _2, name, ...) name #define overload4(_1, _2, _3, _4, name, ...) name #define rep1(n) for (ll i = 0; i < n; i++) #define rep2(i, n) for (ll i = 0; i < n; i++) #define rep3(i, a, b) for (ll i = a; i < b; i++) #define rep4(i, a, b, c) for (ll i = a; i < b; i += c) #define rep(...) overload4(__VA_ARGS__, rep4, rep3, rep2, rep1)(__VA_ARGS__) #define reps1(n) for (ll i = 1; i <= n; i++) #define reps2(i, n) for (ll i = 1; i <= n; i++) #define reps(...) overload2(__VA_ARGS__, reps2, reps1)(__VA_ARGS__) #define rrep1(n) for (int i = n - 1; i >= 0; i--) #define rrep2(i, n) for (int i = n - 1; i >= 0; i--) #define rrep3(i, a, b) for (int i = b - 1; i >= a; i--) #define rrep4(i, a, b, c) for (int i = b - 1; i >= a; i -= c) #define rrep(...) overload4(__VA_ARGS__,rrep4, rrep3, rrep2, rrep1)(__VA_ARGS__) #define rreps1(n) for (long long i = n; i >= 1; i--) #define rreps2(i, n) for (long long i = n; i >= 1; i--) #define rreps(...) overload2(__VA_ARGS__, rreps2, rreps1)(__VA_ARGS__) #define all(a) (a).begin(), (a).end() #define rall(a) (a).rbegin(), (a).rend() #define PI acos(-1.0) #define YES printf("YES\n"), exit(0) #define NO printf("NO\n"), exit(0) #define Yes printf("Yes\n"), exit(0) #define No printf("No\n"), exit(0) #define MINUS printf("-1\n"), exit(0) #define cuot cout // typo #define endk endl //typo constexpr char ln = '\n'; constexpr long long MOD = 998244353LL; constexpr long long LINF = 0x1fffffffffffffff; // 4倍までOK 10^18より大きい constexpr int INF = 0x3fffffff; // 2倍までOK 10^9より大きい template void setcout(T n) {cout << setprecision(n) << fixed;} template constexpr auto min(T... a){return min(initializer_list>{a...});} template constexpr auto max(T... a){return max(initializer_list>{a...});} template bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; } template bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; } template long long acc(const T& a){ return accumulate(all(a), 0LL); } template long double accl(const T& a){ return accumulate(all(a), 0.0L); } template vector mrui(const vector& a) { vector ret(a.size() + 1); for(int i = 0; i < a.size(); i++) { ret[i + 1] = ret[i] + a[i]; } return ret; } template vector> mrui2(const vector> &a) { vector> ret(a.size() + 1, vector(a.front().size() + 1)); for(int i = 0; i < (int)a.size(); i++) { for(int j = 0; j < (int)a.front().size(); j++) { ret[i + 1][j + 1] = ret[i][j + 1] + ret[i + 1][j] - ret[i][j] + a[i][j]; } } return ret; } inline void in(){} template inline void in(Head& head, Tail&... tail){ cin >> head; in(tail...); } #define INT(...) int __VA_ARGS__;in(__VA_ARGS__) #define LL(...) ll __VA_ARGS__;in(__VA_ARGS__) #define ULL(...) ull __VA_ARGS__;in(__VA_ARGS__) #define STR(...) string __VA_ARGS__;in(__VA_ARGS__) #define CHR(...) char __VA_ARGS__;in(__VA_ARGS__) #define DBL(...) double __VA_ARGS__;in(__VA_ARGS__) #define LD(...) ld __VA_ARGS__;in(__VA_ARGS__) #define vec(type, name, ...) vector name(__VA_ARGS__) #define VEC(type, name, size) vector name(size); in(name) #define vv(type, name, h, ...) vector>name(h, vector(__VA_ARGS__)) #define VV(type, name, h, ...) vector>name(h, vector(__VA_ARGS__)); in(name) #define vvv(type, name, h, w, ...) vector>>name(h, vector>(w, vector(__VA_ARGS__))) template ostream &operator<<(ostream &os, const pair &p); // prototype template istream &operator>>(istream &is, pair &p); // prototype template ostream &operator<<(ostream &os, const vector &v); // prototype template ostream &operator<<(ostream &os, const vector> &v); // prototype template ostream &operator<<(ostream &os, const vector>> &v); // prototype template istream &operator>>(istream &is, vector &v); // prototype template ostream &operator<<(ostream &os, const map &mp); // prototype template ostream &operator<<(ostream &os, const set &st); // prototype template ostream &operator<<(ostream &os, const multiset &st); // prototype template ostream &operator<<(ostream &os, queue q); // prototype template ostream &operator<<(ostream &os, deque q); // prototype template ostream &operator<<(ostream &os, stack st); // prototype template ostream &operator<<(ostream &os, priority_queue pq); // prototype //ostream &operator<<(ostream &os, const mint &i); //atcoder // prototype //ostream &operator<<(ostream &os, const vector &v); //atcoder // prototype //ostream &operator<<(ostream &os, const modint &i); //atcoder // prototype //ostream &operator<<(ostream &os, const vector &v); //atcoder // prototype template ostream &operator<<(ostream &os, const pair &p) { os << "(" << p.first << "," << p.second << ")"; return os; } template istream &operator>>(istream &is, pair &p) { is >> p.first >> p.second; return is; } template ostream &operator<<(ostream &os, const vector &v) { for (int i = 0; i < (int)v.size(); i++) { os << v[i] << (i + 1 != (int)v.size() ? " " : ""); } return os; } template ostream &operator<<(ostream &os, const vector> &v) { for (int i = 0; i < (int)v.size(); i++) { os << v[i] << endl; } return os; } template ostream &operator<<(ostream &os, const vector>> &v) { for (int i = 0; i < (int)v.size(); i++) { os << "i = " << i << endl; os << v[i]; } return os; } template istream &operator>>(istream &is, vector &v) { for (T &in : v) { is >> in; } return is; } template ostream &operator<<(ostream &os, const map &mp) { for (auto &[key, val] : mp) { os << key << ": " << val << " "; } return os; } template ostream &operator<<(ostream &os, const set &st) { auto itr = st.begin(); for (int i = 0; i < (int)st.size(); i++) { os << *itr << (i + 1 != (int)st.size() ? " " : ""); itr++; } return os; } template ostream &operator<<(ostream &os, const multiset &st) { auto itr = st.begin(); for (int i = 0; i < (int)st.size(); i++) { os << *itr << (i + 1 != (int)st.size() ? " " : ""); itr++; } return os; } template ostream &operator<<(ostream &os, queue q) { while (q.size()) { os << q.front() << " "; q.pop(); } return os; } template ostream &operator<<(ostream &os, deque q) { while (q.size()) { os << q.front() << " "; q.pop_front(); } return os; } template ostream &operator<<(ostream &os, stack st) { while (st.size()) { os << st.top() << " "; st.pop(); } return os; } template ostream &operator<<(ostream &os, priority_queue pq) { while (pq.size()) { os << pq.top() << " "; pq.pop(); } return os; } /*ostream &operator<<(ostream &os, const mint &i) { //AtCoder os << i.val(); return os; }*/ /*ostream &operator<<(ostream &os, const vector &v) { //AtCoder for (int i = 0; i < (int)v.size(); i++) { os << v[i].val() << (i + 1 != (int)v.size() ? " " : ""); } return os; }*/ /*ostream &operator<<(ostream &os, const modint &i) { //AtCoder os << i.val(); return os; }*/ /*ostream &operator<<(ostream &os, const vector &v) { //AtCoder for (int i = 0; i < (int)v.size(); i++) { os << v[i].val() << (i + 1 != (int)v.size() ? "" : ""); } return os; }*/ //#pragma GCC target("avx2") //#pragma GCC optimize("O3") //#pragma GCC optimize("unroll-loops") int main() { ll t; cin >> t; rep(t) { ll l, r, a, b; cin >> l >> r >> a >> b; cout << max(a * l + b, a * r + b) << endl; } }