import sys ii = lambda: int(input()) mi = lambda: map(int, input().split()) li = lambda: list(mi()) for _ in range(ii()): l, r, a, b = mi() print(max(a * l + b, a * r + b))