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