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