def one_str(): return input() def many_int(): return list(map(int, input().split())) input_count = 0 T = int(input()) def calc(N, M, K): count = 0 K = K%M if K >= M-N: return 0 else: return K for i in range(T): N, M, K = many_int() print(calc(N,M,K))