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