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