t = int(input()) for _ in range(t): L,R,A,B = map(int,input().split()) res = -(2*10**6) for x in range(L,R+1): tmp = A*x + B res = max(tmp,res) print(res)