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