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