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