import sys readline = sys.stdin.readline T = int(readline()) for _ in range(T): L, R, A, B = map(int,readline().split()) if A < 0: print(L * A + B) else: print(R * A + B)