for _ in [0] * int(input()): n, m, k = map(int, input().split()) a = k % m if(m - n <= a): print(0) else: print(a % (m - n))