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