import sys input = sys.stdin.readline T=int(input()) for tests in range(T): N,M,K=map(int,input().split()) X=K%M if M-N<=X: print(0) else: print(X)