Under construction

Still being built. Things may change

Depth First Search

Time limit6sMemory limit1024 MB

Summary
Count subsets of the m extra edges so that tree T, plus the chosen edges, is a DFS tree from one of the k special vertices.
Level

Hard8 of 10

Topics
Tree, DFS, Dynamic programming, Combinatorics
Solved
No attempts yet

Problem

Depth-first search is a common search algorithm. Using this algorithm, we can obtain a tree TT from an undirected connected graph G=(V,E)G = (V,E) with no self-loops nor parallel edges, and a certain starting point ss.

The algorithm can be described as follows:

  • Set the stack SS to be empty, and let T=(V,∅)T = (V, \emptyset), which means that the edge set of TT is initially empty.
  • First, push the starting point ss into SS.
  • Visit the top vertex uu of the stack and mark uu as visited.
  • If there is a vertex vv adjacent to uu and not yet visited, arbitrarily select one from these vertices and let (u,v)(u, v) be added to the edge set of TT. Then, push vv into the stack SS, and go back to step 3. If there is no such vertex, pop uu out of the stack.

It can be proved that when GG is a connected graph, the algorithm will obtain a certain spanning tree TT of GG. However, the tree TT obtained by the algorithm may not be unique, depending on the search order, i.e., the vertex selected in step 4. If a specific search order can be chosen so that the tree obtained by the algorithm is exactly TT, then we call TT an ss-dfs tree of GG with respect to the starting point ss.

Now, given a tree TT with nn vertices labeled from 11 to nn, and an additional mm edges, we guarantee that these mm edges are distinct and connect different vertices, and are different from the n−1n-1 tree edges in TT. We call these additional mm edges non-tree edges. Among these nn vertices, we specify exactly kk vertices as special vertices.

You want to know how many ways there are to select a subset of these mm non-tree edges (you can possibly select none) such that, after the tree edges of TT and the selected non-tree edges are combined to form a graph GG, there exists a special vertex ss such that TT is an ss-dfs tree of GG.

Since the answer may be very large, output the number of solutions modulo (109+7)(10^9+7).

Input

The first line of input contains an integer cc, which represents the test case number. c=0c = 0 represents that this test case is a sample test.

The second line of input contains three positive integers n,m,kn, m, k, which represent the number of vertices, the number of non-tree edges, and the number of special vertices.

Then n−1n-1 lines follow, each containing two positive integers u,vu, v, representing a tree edge of TT. It is guaranteed that these n−1n-1 edges form a tree.

Then mm lines follow, each containing two positive integers a,ba, b, representing a non-tree edge. It is guaranteed that (a,b)(a, b) does not coincide with an edge on the tree and there are no duplicate edges.

The last line of input contains kk positive integers s1,s2,...,sks_1, s_2, ..., s_k, representing the labels of the kk special vertices. It is guaranteed that s1,s2,...,sks_1, s_2, ..., s_k are distinct from each other.

Output

Output a line containing an integer, representing the number of solutions, taken modulo (109+7)(10^9+7).

Constraints

For all test data, it is guaranteed that 1≤k≤n≤5⋅1051 \leq k \leq n \leq 5\cdot 10^5 and 1≤m≤5⋅1051 \leq m \leq 5\cdot 10^5.

Examples1

  1. Example 1

    Input
    0
    4 2 2
    1 2
    2 3
    3 4
    1 3
    2 4
    2 3
    
    Expected output
    3