T = int(input()) for _ in range(T): n,m,k = map(int, input().split()) a = k % m if a >= m - n: a = 0 print(a)