t = int(input()) for _ in range(t): n, m, k = map(int, input().split()) a_0 = k % m ans = a_0 for i in range(1, n+1): ans %= (m - i) print(ans)