T = int(input()) for _ in range(T): l, r, a, b = map(int, input().split()) f = lambda x: a*x + b print(max(f(l), f(r)))