x = int(eval(input()))

a = int(eval(input()))

b = int(eval(input()))



x = x-a

num = x//b



print((x-(num*b)))
x = eval(input())

a = eval(input())

b = eval(input())

x -= a

print(x % b)
x = int(eval(input()))
a = int(eval(input()))
b = int(eval(input()))
x = x - a
num = x // b
print((x - (num * b)))

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

-x = int(eval(input())) -a = int(eval(input())) -b = int(eval(input())) -x = x - a -num = x // b -print((x - (num * b))) +x = eval(input()) +a = eval(input()) +b = eval(input()) +x -= a +print(x % b)