#P17454. 迭代不动点 / Iterated Fixed Points

迭代不动点 / Iterated Fixed Points

Problem Description

Due to differences in the performance of the judging machines, the time limit of this problem has been adjusted to 2 s.

Given three integers n,k,pn,k,p.

Consider all functions

f:{1,2,…,n}→{1,2,…,n}.f:\{1,2,\ldots,n\}\to\{1,2,\ldots,n\}.

Let fkf^k denote the kk-th iteration of the function ff. If x∈{1,2,…,n}x\in\{1,2,\ldots,n\} satisfies

fk(x)=x,f^k(x)=x,

then xx is called a kk-th order iterated fixed point of ff.

Find the number of functions ff that have exactly pp kk-th order iterated fixed points. Output the answer modulo 109+710^9+7.

Input Format

This problem contains multiple test cases.

The first line contains an integer TT (1≤T≤104)(1\le T\le 10^4), indicating the number of test cases.

The next TT lines each contain three integers n,k,pn,k,p (1≤n,k≤106,0≤p≤n)(1\le n,k\le 10^6,0\le p\le n).

It is guaranteed that the sum of nn over all test cases does not exceed 10610^6.

Output Format

For each test case, output one integer per line, representing the result modulo 109+710^9+7.

7
3 2 2
2 1 0
3 1 0
3 2 0
3 3 3
4 2 4
4 1 2
12
1
8
2
3
10
54

Hint

Translated by ChatGPT 5