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