X = int(eval(input()))

A = int(eval(input()))

B = int(eval(input()))

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

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

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

-X = int(eval(input())) -A = int(eval(input())) -B = int(eval(input())) +X, A, B = [int(eval(input())) for _ in range(3)]