#SL2310C. Many Topological Problems
Many Topological Problems
Many Topological Problems
Once you created the following problem:
Topological Problem
You are given a labeled rooted tree with vertices and an integer . We call a permutation of length good if and for each with a parent .
Find the number of good permutations.
Now, thinking this problem is too easy, you create the following problem:
Many Topological Problems
You are given two integers . For all different labeled rooted trees with vertices, find the sum of the answer to the Topological Problem of , modulo .
Please solve Many Topological Problems.
Two labeled rooted trees are considered different, if and only if their roots differ, or one edge exists in one tree but not in the other.
Input
The first line contains a single integer , denoting the number of test cases.
For each test case, the only line contains two integers .
Output
For each test case, output one line with an integer denoting the answer.
Example
3
2 2
5 1
114514 1919
2
120
354463397