def Main(): for _ in range(int(input())): l,r,a,b=map(int,input().split()) ans=max(l*a+b,r*a+b) if l<=0<=r: ans=max(ans,b) print(ans) Main()