#include using namespace std; int main() { int t; cin >> t; for (int i = 0; i < t; i++ ) { int l, r, a, b; cin >> l >> r >> a >> b; if (a < 0) { cout << a * l + b << endl; } else { cout << a * r + b << endl; } } }