logo AlgoBeat OnlineJudge
登录 注册

#217562. [ICPC 2018 Xuzhou R] Rikka with Intersections of Paths

内存限制:512 MiB 时间限制:10000 ms 标准输入输出
题目类型:VJudge(洛谷) 评测方式:VJudge
上传者: 匿名

题目描述

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.

输入格式

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.

输出格式

For each test case, output a single line with a single integer, the number of different strategies meeting the requirement modulo .

样例

样例输入 1

1
3 6 2
1 2
1 3
1 1
2 2
3 3
1 2
1 3
2 3

样例输出 1

10