ANS = [] for _ in range(int(input())): N,M,K = map(int,input().split()) ANS.append( K%M if K%M < M-N else 0 ) print(*ANS)