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