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