import sys input = sys.stdin.readline T = int(input()) for _ in range(T): N, M, K = map(int, input().split()) a = K % M if M-a <= N: print(0) else: print(a)