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