t = int(input()) for i in range(t): l, r, a, b = map(int, input().split()) ans = -float("inf") for x in range(l, r+1): y = a * x + b ans = max(ans, y) print(ans)