#abc152f. [abc152_f]Tree and Constraints

[abc152_f]Tree and Constraints

Problem Statement

We have a tree with NN vertices numbered 11 to NN. The ii-th edge in this tree connects Vertex aia_i and Vertex bib_i.
Consider painting each of these edges white or black. There are 2N12^{N-1} such ways to paint the edges. Among them, how many satisfy all of the following MM restrictions?

  • The ii-th (1leqileqM)(1 \\leq i \\leq M) restriction is represented by two integers uiu_i and viv_i, which mean that the path connecting Vertex uiu_i and Vertex viv_i must contain at least one edge painted black.

Constraints

  • 2leqNleq502 \\leq N \\leq 50
  • 1leqai,bileqN1 \\leq a_i,b_i \\leq N
  • The graph given in input is a tree.
  • 1leqMleqmin(20,fracN(N1)2)1 \\leq M \\leq \\min(20,\\frac{N(N-1)}{2})
  • 1lequi<vileqN1 \\leq u_i < v_i \\leq N
  • If inot=ji \\not= j, either uinot=uju_i \\not=u_j or vinot=vjv_i\\not=v_j
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

NN a1a_1 b1b_1 :: aN1a_{N-1} bN1b_{N-1} MM u1u_1 v1v_1 :: uMu_M vMv_M

Output

Print the number of ways to paint the edges that satisfy all of the MM conditions.


Sample Input 1

3
1 2
2 3
1
1 3

Sample Output 1

3

The tree in this input is shown below:

Figure

All of the MM restrictions will be satisfied if Edge 11 and 22 are respectively painted (white, black), (black, white), or (black, black), so the answer is 33.


Sample Input 2

2
1 2
1
1 2

Sample Output 2

1

The tree in this input is shown below:

Figure

All of the MM restrictions will be satisfied only if Edge 11 is painted black, so the answer is 11.


Sample Input 3

5
1 2
3 2
3 4
5 3
3
1 3
2 4
2 5

Sample Output 3

9

The tree in this input is shown below:

Figure


Sample Input 4

8
1 2
2 3
4 3
2 5
6 3
6 7
8 6
5
2 7
3 5
1 6
2 8
7 8

Sample Output 4

62

The tree in this input is shown below:

Figure