T = int(input()) for i in range(T): N, M, K = map(int, input().split()) a = K%M cnt = 1 while cnt <= N: if a >= (M-cnt): a %= (M-cnt) cnt += 1 else: if a < (M-N): print(a) cnt = N+1 else: print(0) cnt = N+1