cash = int(eval(input()))

price_cake = int(eval(input()))

price_donut = int(eval(input()))

print(((cash-price_cake)%price_donut))
cash, price_cake, price_donut = [int(eval(input())) for i in range(3)]

print(((cash-price_cake)%price_donut))
cash = int(eval(input()))
price_cake = int(eval(input()))
price_donut = int(eval(input()))
print(((cash - price_cake) % price_donut))

cash, price_cake, price_donut = [int(eval(input())) for i in range(3)]
print(((cash - price_cake) % price_donut))

-cash = int(eval(input())) -price_cake = int(eval(input())) -price_donut = int(eval(input())) +cash, price_cake, price_donut = [int(eval(input())) for i in range(3)]