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