#include using namespace std; using ll = long long; #define overload3(_1, _2, _3, name, ...) name #define rep1(n) for(ll _ = 0; _ < (n); ++_) #define rep2(i, n) for(ll i = 0; i < (n); ++i) #define rep3(i, a, b) for(ll i = (a); i < (b); ++i) #define rep(...) overload3(__VA_ARGS__, rep3, rep2, rep1)(__VA_ARGS__) #define all(x) (x).begin(), (x).end() template using vec = vector; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); int T; cin >> T; rep(T){ int L, R, A, B; cin >> L >> R >> A >> B; if(A >= 0) cout << R * A + B << "\n"; else cout << L * A + B << "\n"; } }