Directing the Tree

Count the orientations of a tree's edges such that every given vertex pair has a directed path one way or the other, modulo 1e9+7.

Hard8TreeDFSDynamic programmingCombinatoricsNo attempts yetTime limit2sMemory limit256 MB

Problem

You are given a tree with NN nodes, labeled with distinct integers from 11 to NN. You are also given MM node pairs of the tree, (a1,b1),(a2,b2),,(aM,bM)(a_1, b_1), (a_2, b_2), \dots, (a_M, b_M).

Direct every edge of the tree so that for each given pair (ai,bi)(a_i, b_i) there is a path from aia_i to bib_i, or a path from bib_i to aia_i. Count the ways to do this. The count can be very large, so print it modulo 109+710^9 + 7.

A tree is a graph with NN nodes and N1N - 1 edges in which every node has a path to every other node.

Input

The first line contains the number of nodes NN and the number of given node pairs MM (1N,M3×1051 \le N, M \le 3 \times 10^5).

Each of the next N1N - 1 lines contains the labels of two nodes joined by an edge.

The iith of the next MM lines contains two different positive integers aia_i and bib_i, the labels of the nodes in the iith pair. All node pairs are mutually different.

Output

Print one line with the number of ways to direct the edges of the tree so that the requirement holds, modulo 109+710^9 + 7.