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)