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 if cnt > N: print(a) else: if a < (M-N): print(a) cnt = N+1 else: print(0) cnt = N+1