#include using namespace std; int main(){ int T; cin >> T; while(T--){ int L, R, A, B; cin >> L >> R >> A >> B; if (A >= 0){ cout << R * A + B << endl; } else{ cout << L * A + B << endl; } } }