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