t = int(input()) for i in range(t): l,r,a,b = map(int,input().split()) if a >= 0: print(a*r+b) else: print(a*l+b)