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