#P7853. Jumping on a Cactus
Jumping on a Cactus
Jumping on a Cactus
Problem Description
It is preferrable to read the pdf statment. Cuber QQ has recently learned jumping on graphs. He now wants to demonstrate his skills on a cactus . Recall that, cactus refers to a graph with every edge appearing in at most one cycle . If you do not know what a cycle is, formally, a cycle of length denotes an edge sequence $(u_1,u_2), (u_2,u_3),\ldots,(u_{k-1},u_k),(u_k,u_1)$. Assuming you are given an undirected cactus , with vertices and edges. A jumping on the cactus can be thought of as a visit to all vertices where every vertex is visited exactly once. That can be represented with a permutation of to , , and they are visited in order. Cuber QQ also wishes his jumping to be gradually approaching or distancing away from a particular node . Concretely, we define to be the distance from to (the minimum edges needs to be passed through from to ). A jumping is defined to be monotonic if, for all edges , when is visited before , or, for all edges , when is visited after . Count the number of different monotonic jumping plans. Since the answer can be very large, you should print the answer modulo .
Input
The first line of the input contains a single integer (), denoting the number of test cases. For each of the next cases: The first line contains three space-separated integers , , (, , ). The -th of the next lines contains two space-separated integers , (, ). It is guaranteed that . There are at most test cases where .
Output
For each test case, output one line contains one integer denoting the answer modulo .
Notes
For the example, looks like:
is the index of reference vertex.
There are correct permutations:
.
.
.
.
.
.
.
.
Sample Input
1
6 7 3
6 2
5 6
1 5
1 2
3 2
3 2
4 2
Sample Output
8
Source
2020 Multi-University Training Contest 8