t=int(input()) for q in range(t): l,r,a,b=map(int,input().split()) print(max(l*a+b,r*a+b))