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