#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int,int> P; #define REP(i,n) for(int i=0;i<int(n);i++) int main(void){ cin.tie(nullptr); ios_base::sync_with_stdio(false); int i,j,k; int T; cin >> T; REP(tc,T){ int L,R,A,B; cin >> L >> R >> A >> B; cout << max(A*L+B,A*R+B) << endl; } return 0; }