for _ in range(int(input())):
    l,r,a,b = map(int,input().split())
    print(l*a+b if a<0 else r*a+b)