def Main(): t=int(input()) for _ in range(t): l,r,a,b=map(int,input().split()) foo=a*l+b bar=a*r+b print(max(foo,bar)) Main()