import sys readline=sys.stdin.readline T=int(readline()) for t in range(T): L,R,A,B=map(int,readline().split()) ans=max(A*L+B,A*R+B) print(ans)