import sys input = sys.stdin.buffer.readline t = int(input()) def divide(n): res = set() for i in range(1, int(n ** 0.5) + 1): if n % i == 0: res.add(i) res.add(n // i) return res for _ in range(t): n, m, k = map(int, input().split()) num = k % m mn = m - n yakusu = divide(num) # ans = -1 # for a in yakusu: # if mn <= a: # ans = 0 # break # if ans == -1: # ans = num % mn if mn <= num: print(0) else: print(num % mn)