#yuki1926 t=int(input()) for i in range(t): n,m,k=map(int,input().split()) if k%m>=m-n: print(0) else: print(k%m)