t = int(input()) for i in range(n): l,r,a,b = map(int,input().split()) print(a*(l,r)[a>=0]+b)