for t in range(int(input())): n,m,k=map(int,input().split()) ans=k%m if m-n<=ans: ans=0 print(ans)