x=int(eval(input()))

a=int(eval(input()))

b=int(eval(input()))

x=x-a

re=x % b





print(re)



x=int(input())

a=int(input())

b=int(input())



print((x-a)%b)

x = int(eval(input()))
a = int(eval(input()))
b = int(eval(input()))
x = x - a
re = x % b
print(re)

x = int(input())
a = int(input())
b = int(input())
print((x - a) % b)

-x = int(eval(input())) -a = int(eval(input())) -b = int(eval(input())) -x = x - a -re = x % b -print(re) +x = int(input()) +a = int(input()) +b = int(input()) +print((x - a) % b)