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