#P17424. [ICPC 2018 Xuzhou R] Rikka with Intersections of Paths
[ICPC 2018 Xuzhou R] Rikka with Intersections of Paths
Problem Description
Rikka has a tree with vertices numbered from to .
Meanwhile, Rikka has marked simple paths in , the -th of which is between the vertices and , where some of them could be the same path.
Now, Rikka wants to know in how many different strategies she can select paths from the marked paths such that those selected paths share at least one common vertex.
Input Format
The input contains several test cases, and the first line contains a single integer (), the number of test cases.
For each test case, the first line contains three integers (), the size of the tree , (), the number of marked paths, and ().
The following lines describe the tree . Each of them contains two integers and (, ), representing an edge between the vertices and .
The following lines describe all marked simple paths in the tree. The -th of them contains two integers and ().
The input guarantees that the sum of and the sum of in all test cases are at most respectively.
Output Format
For each test case, output a single line with a single integer, the number of different strategies meeting the requirement modulo .
1
3 6 2
1 2
1 3
1 1
2 2
3 3
1 2
1 3
2 3
10