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