You went shopping to buy cakes and donuts with X yen (the currency of Japan).  First, you bought one cake for A yen at a cake shop. Then, you bought as many donuts as possible for B yen each, at a donut shop.  How much do you have left after shopping?
inf = [int(input()) for i in range(3)]
a = inf[0]-inf[1]
b = a/inf[2]
ans = a-b *inf[2]
print(ans)
inf = [int(input()) for i in range(3)]
a = inf[0]-inf[1]
b = int(a/inf[2])
ans = a-b *inf[2]
print(ans)