for t in range(int(input())): L,R,A,B=map(int,input().split()) print(max(A*L,A*R)+B)