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