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