X = int(eval(input()))

A = int(eval(input()))

B = int(eval(input()))



bf = X - A

while bf >= B:

    bf -= B



print(bf)
X, A, B = [int(eval(input())) for i in range(3)]

X -= A

X %= B



print(X)
X = int(eval(input()))
A = int(eval(input()))
B = int(eval(input()))
bf = X - A
while bf >= B:
    bf -= B
print(bf)

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

-X = int(eval(input())) -A = int(eval(input())) -B = int(eval(input())) -bf = X - A -while bf >= B: -    bf -= B -print(bf) +X, A, B = [int(eval(input())) for i in range(3)] +X -= A +X %= B +print(X)