for _ in [0] * int(input()): l, r, a, b = map(int, input().split()) print(max(a * l + b, a * r + b))