x = int(eval(input()))

a = int(eval(input()))

b = int(eval(input()))

c = x - a

d = c%b

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

print(((x-a)%b))
x = int(eval(input()))
a = int(eval(input()))
b = int(eval(input()))
c = x - a
d = c % b
print(d)

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

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