T=int(input()) for tests in range(T): L,R,A,B=map(int,input().split()) print(max(A*L+B,A*R+B))