t = int(input()) for i in range(t): l,r,a,b = map(int,input().split()) ma = 10**18*-1 for j in range(l,r+1): ma = max(ma,a*j+b) print(ma)