a, b, c = [int(eval(input())) for i in range(3)]

print(((a - b) % c))
x, a, b = [int(eval(input())) for _ in range(3)]

print(((x-a)%b))

a, b, c = [int(eval(input())) for i in range(3)]
print(((a - b) % c))

x, a, b = [int(eval(input())) for _ in range(3)]
print(((x - a) % b))

-a, b, c = [int(eval(input())) for i in range(3)] -print(((a - b) % c)) +x, a, b = [int(eval(input())) for _ in range(3)] +print(((x - a) % b))