t=int(input()) def zen(l,r,a,b): x1,x2=a*l+b,a*r+b return max(x1,x2) for _ in range(t): a,b,c,d=map(int,input().split()) print(zen(a,b,c,d))