This page is still under construction.

Parts of this page are still being built. What you see may change.

Šarenlist

Time limit1sMemory limit512 MB

Summary
Count the ways to color the edges of a tree with k colors so that each of m given paths contains at least two different colors, modulo 1e9+7.
Level

Hard8 of 10

Topics
Combinatorics, Tree, Bit manipulation, Dynamic programming
Solved
No attempts yet

Problem

Warm summer night. Vito and his friend, Karlo, are lying in a forest clearing and watching the stars. Suddenly, Vito exclaims "Karlo, look! The trees around us are changing colors!" "Wooow so colorful" said Karlo, amazed. Indeed, the tree branches in the forest started to change colors.

Fascinated by the colorful trees, Vito and Karlo noticed a couple of facts about them. Each of the trees they are looking at can be represented as a tree graph, i.e. an undirected graph in which there exists a unique path between each pair of nodes. The trees they are looking at have the property that each edge of the tree is colored in one of kk different colors. Some of the paths on the tree are colorful, meaning that such a path contains edges of at least two different colors.

Morning has arrived and the tree magic is now lost. In order to relive this experience, Vito and Karlo ask you to solve the following problem. Given a tree and mm pairs of nodes on the tree, determine the number of different colorings of the tree edges so that each of the mm paths determined by the mm pairs of nodes is colorful. Since this number can be very large, output it modulo 109+710^9 + 7.

Input

The first line contains three positive integers nn, mm and kk (3≤n≤603 ≤ n ≤ 60, 1≤m≤151 ≤ m ≤ 15, 2≤k≤1092 ≤ k ≤ 10^9), the number of nodes in the tree, the number of paths required to be colorful and the number of possible colors for the tree branches, respectively.

The ii-th of the next n−1n - 1 lines contains a pair of positive integers a_ia\_i and b_ib\_i (1≤a_i,b_i≤n1 ≤ a\_i , b\_i ≤ n), representing an edge of the tree.

The jj-th of the next mm lines contains a pair of positive integers c_jc\_j and d_jd\_j (1≤c_j,d_j≤n1 ≤ c\_j , d\_j ≤ n), the labels of the endpoints of the paths which are required to be colorful. The nodes c_jc\_j and d_jd\_j are not neighbouring.

Output

In the only line print the number of ways to color the tree edges so that each of the mm given paths is colorful, modulo 109+710^9 + 7.

Hint

Clarification of the first example: The tree consists of only two edges, both part of a colorful path between the nodes 1 and 3. So, the two edges must have a different color. One such coloring is obtained by coloring the edge 1-2 in color 1, and 2-3 in color 2, while the other is obtained by switching these colors so that 1-2 has color 2, and 2-3 has color 1.

Examples3

  1. Example 1

    Input
    3 1 2
    1 2
    2 3
    1 3
    
    Expected output
    2
    
  2. Example 2

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

    Input
    4 3 3
    1 2
    2 3
    4 2
    1 4
    1 3
    4 3
    
    Expected output
    6