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