x = int(eval(input()))

a = int(eval(input()))

b = int(eval(input()))

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

print(((l[0]-l[1]) % l[2]))
x = int(eval(input()))
a = int(eval(input()))
b = int(eval(input()))
print(((x - a) % b))

l = [int(eval(input())) for i in range(3)]
print(((l[0] - l[1]) % l[2]))

-x = int(eval(input())) -a = int(eval(input())) -b = int(eval(input())) -print(((x - a) % b)) +l = [int(eval(input())) for i in range(3)] +print(((l[0] - l[1]) % l[2]))