#include //cin, cout #include //vector #include //sort,min,max,count using namespace std; int main() { int T, N, M, K; cin >> T; for (int i = 0; i < T; i++) { cin >> N >> M >> K; vector a(N + 1); a[0] = K % M; for (int j = 1; j <= N; j++) { a[j] = a[j - 1] % (M - j); } cout << a[N] << endl; } return 0; }