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