x,a,b = [int(eval(input())) for i in range(3)]

print(((x-a)%b))
print(((int(eval(input()))-int(eval(input())))%int(eval(input()))))
x, a, b = [int(eval(input())) for i in range(3)]
print(((x - a) % b))

print(((int(eval(input())) - int(eval(input()))) % int(eval(input()))))

-x, a, b = [int(eval(input())) for i in range(3)] -print(((x - a) % b)) +print(((int(eval(input())) - int(eval(input()))) % int(eval(input()))))