import sys def input(): return sys.stdin.readline()[:-1] t=int(input()) for _ in range(t): L,R,A,B=map(int,input().split()) if A>0: print(A*R+B) else: print(A*L+B)