print(((int(eval(input())) - int(eval(input()))) % int(eval(input()))))
X, A, B = (int(eval(input())) for i in range(3))

print(((X - A) % B))
print(((int(eval(input())) - int(eval(input()))) % int(eval(input()))))

X, A, B = (int(eval(input())) for i in range(3))
print(((X - A) % B))

-print(((int(eval(input())) - int(eval(input()))) % int(eval(input())))) +X, A, B = (int(eval(input())) for i in range(3)) +print(((X - A) % B))