import math



X = int(eval(input()))

price = [int(eval(input())) for i in range(2)]



haveMoney = X

haveMoney = X - price[0]

numDonuts = math.floor(haveMoney/price[1])

haveMoney = haveMoney - price[1] * numDonuts



print(haveMoney)
X = int(eval(input()))

price = [int(eval(input())) for i in range(2)]

print(((X-price[0])%price[1]))
import math

X = int(eval(input()))
price = [int(eval(input())) for i in range(2)]
haveMoney = X
haveMoney = X - price[0]
numDonuts = math.floor(haveMoney / price[1])
haveMoney = haveMoney - price[1] * numDonuts
print(haveMoney)

X = int(eval(input()))
price = [int(eval(input())) for i in range(2)]
print(((X - price[0]) % price[1]))

-import math - -haveMoney = X -haveMoney = X - price[0] -numDonuts = math.floor(haveMoney / price[1]) -haveMoney = haveMoney - price[1] * numDonuts -print(haveMoney) +print(((X - price[0]) % price[1]))