T = int(input()) for _ in range(T): l,r,a,b = map(int,input().split()) A = l * a + b B = r * a + b print(max(A,B))