#K79242. Toy Distribution

    ID: 35265 Type: Default 1000ms 256MiB

Toy Distribution

Toy Distribution

You are given a number of test cases. For each test case, you are provided with two integers M and N. The problem is to determine the number of ways to distribute M types of toys into N containers under the following rule:

  • If M > N, it is impossible to distribute the toys properly, and the answer is 0.
  • If M ≤ N, the number of ways is given by the factorial of M, i.e. \(M!\), computed modulo \(10^9+7\).

Recall that the factorial of a non-negative integer \(M\) is defined as:

\[ M! = 1 \times 2 \times 3 \times \cdots \times M,\]

with the special case \(0! = 1\). The final answer for each test case should be computed as:

\[ \text{answer} = \begin{cases} 0, & \text{if } M > N,\\ M! \mod 1000000007, & \text{if } M \le N. \end{cases}\]

Process each test case independently and output the result for each on a new line.

inputFormat

The first line contains a single integer T, the number of test cases. Each of the following T lines contains two space-separated integers M and N:

  • M: the number of toy types.
  • N: the number of containers.

Example:

3
2 3
3 3
4 5

outputFormat

For each test case, output a single line containing the number of ways to distribute the toys according to the rules described above.

Example:

2
6
24
## sample
3
2 3
3 3
4 5
2

6 24

</p>