T = int(input()) for _ in range(T): ls = list(map(int, input().split())) if ls[2] >= 0: print(ls[2] * ls[1] + ls[3]) else: print(ls[2] * ls[0] + ls[3])