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

x, a, b = list(map(int, [eval(input()) for i in [0] * 3]))
print(((x - a) % b))

-x, a, b = list(map(int, [eval(input()) for i in range(3)])) +x, a, b = list(map(int, [eval(input()) for i in [0] * 3]))