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