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