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