T = int(input()) for i in range(T): L,R,A,B = (int(x) for x in input().sprit()) if A>0: print(A*R+B) else: print(A*L+B)