T = int(input()) for _ in range(T): N, M, K = map(int, input().split()) if N >= M - K % M: print(0) else: print(K % M)