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