t=int(input()) for _ in range(t): l,r,a,b=map(int,input().split()) ans=-float("inf") for i in range(l,r+1): ans=max(ans,a*i+b) print(ans)