X = int( eval(input()))

A = int( eval(input()))

B = int( eval(input()))



X1 = X -A



Dcount = X1 // B



Dprice = B * Dcount



print((X1 - Dprice))

X = int( eval(input()))

A = int( eval(input()))

B = int( eval(input()))



X1 = X -A

print((X1 % B))

X = int(eval(input()))
A = int(eval(input()))
B = int(eval(input()))
X1 = X - A
Dcount = X1 // B
Dprice = B * Dcount
print((X1 - Dprice))

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

-Dcount = X1 // B -Dprice = B * Dcount -print((X1 - Dprice)) +print((X1 % B))