from collections import defaultdict





def dfs(s, t):

    visited = 0

    q = [(s, 0)]

    while q:

        v, used = q.pop()

        if v == t:

            return used

        visited |= used

        for lb, u in graph[v]:

            if lb & visited:

                continue

            q.append((u, used | lb))





n = int(eval(input()))

graph = [[] for _ in range(n + 1)]

for i in range(n - 1):

    a, b = list(map(int, input().split()))

    lb = 1 << i

    graph[a].append((lb, b))

    graph[b].append((lb, a))



conditions = []

m = int(eval(input()))

for i in range(m):

    u, v = list(map(int, input().split()))

    conditions.append(dfs(u, v))



link_conditions = [int(''.join(b), 2) for b in zip(*list(map(('{:0' + str(n - 1) + 'b}').format, conditions)))]



dp = defaultdict(int)

dp[0] = 1

for lc in link_conditions:

    for fulfilled, pattern in list(dp.items()):

        dp[fulfilled | lc] += pattern

print((dp[(1 << m) - 1]))

# https://atcoder.jp/contests/abc152/submissions/9619555



import numpy as np

import sys

readline = sys.stdin.readline



N = int(readline())

graph = [[] for _ in range(N + 1)]

for i in range(N - 1):

    a, b = list(map(int, readline().split()))

    lb = 1 << i

    graph[a].append((lb, b))

    graph[b].append((lb, a))



M = int(readline())





def get_path(U, V):

    visited = 0

    q = [(U, 0)]

    while q:

        v, used = q.pop()

        if v == V:

            return used

        visited |= used

        for lb, u in graph[v]:

            if lb & visited:

                continue

            q.append((u, used | lb))





condition_path = []

for i in range(M):

    u, v = list(map(int, readline().split()))

    condition_path.append(get_path(u, v))





def popcnt(n):

    c = (n & 0x5555555555555555) + ((n >> 1) & 0x5555555555555555)

    c = (c & 0x3333333333333333) + ((c >> 2) & 0x3333333333333333)

    c = (c & 0x0f0f0f0f0f0f0f0f) + ((c >> 4) & 0x0f0f0f0f0f0f0f0f)

    c = (c & 0x00ff00ff00ff00ff) + ((c >> 8) & 0x00ff00ff00ff00ff)

    c = (c & 0x0000ffff0000ffff) + ((c >> 16) & 0x0000ffff0000ffff)

    c = (c & 0x00000000ffffffff) + ((c >> 32) & 0x00000000ffffffff)

    return c





sgn = np.where(popcnt(np.arange(1 << M)) % 2, -1, 1)

S = np.zeros(1 << M, np.int64)

for i in range(M):

    S[1 << i:1 << (i + 1)] = S[:1 << i] | condition_path[i]





n_edges = popcnt(S)

x = 1 << (N - 1 - n_edges)

answer = np.sum(x * sgn)

print(answer)
from collections import defaultdict


def dfs(s, t):
    visited = 0
    q = [(s, 0)]
    while q:
        v, used = q.pop()
        if v == t:
            return used
        visited |= used
        for lb, u in graph[v]:
            if lb & visited:
                continue
            q.append((u, used | lb))


n = int(eval(input()))
graph = [[] for _ in range(n + 1)]
for i in range(n - 1):
    a, b = list(map(int, input().split()))
    lb = 1 << i
    graph[a].append((lb, b))
    graph[b].append((lb, a))
conditions = []
m = int(eval(input()))
for i in range(m):
    u, v = list(map(int, input().split()))
    conditions.append(dfs(u, v))
link_conditions = [
    int("".join(b), 2)
    for b in zip(*list(map(("{:0" + str(n - 1) + "b}").format, conditions)))
]
dp = defaultdict(int)
dp[0] = 1
for lc in link_conditions:
    for fulfilled, pattern in list(dp.items()):
        dp[fulfilled | lc] += pattern
print((dp[(1 << m) - 1]))

# https://atcoder.jp/contests/abc152/submissions/9619555
import numpy as np
import sys

readline = sys.stdin.readline
N = int(readline())
graph = [[] for _ in range(N + 1)]
for i in range(N - 1):
    a, b = list(map(int, readline().split()))
    lb = 1 << i
    graph[a].append((lb, b))
    graph[b].append((lb, a))
M = int(readline())


def get_path(U, V):
    visited = 0
    q = [(U, 0)]
    while q:
        v, used = q.pop()
        if v == V:
            return used
        visited |= used
        for lb, u in graph[v]:
            if lb & visited:
                continue
            q.append((u, used | lb))


condition_path = []
for i in range(M):
    u, v = list(map(int, readline().split()))
    condition_path.append(get_path(u, v))


def popcnt(n):
    c = (n & 0x5555555555555555) + ((n >> 1) & 0x5555555555555555)
    c = (c & 0x3333333333333333) + ((c >> 2) & 0x3333333333333333)
    c = (c & 0x0F0F0F0F0F0F0F0F) + ((c >> 4) & 0x0F0F0F0F0F0F0F0F)
    c = (c & 0x00FF00FF00FF00FF) + ((c >> 8) & 0x00FF00FF00FF00FF)
    c = (c & 0x0000FFFF0000FFFF) + ((c >> 16) & 0x0000FFFF0000FFFF)
    c = (c & 0x00000000FFFFFFFF) + ((c >> 32) & 0x00000000FFFFFFFF)
    return c


sgn = np.where(popcnt(np.arange(1 << M)) % 2, -1, 1)
S = np.zeros(1 << M, np.int64)
for i in range(M):
    S[1 << i : 1 << (i + 1)] = S[: 1 << i] | condition_path[i]
n_edges = popcnt(S)
x = 1 << (N - 1 - n_edges)
answer = np.sum(x * sgn)
print(answer)

-from collections import defaultdict +# https://atcoder.jp/contests/abc152/submissions/9619555 +import numpy as np +import sys + +readline = sys.stdin.readline +N = int(readline()) +graph = [[] for _ in range(N + 1)] +for i in range(N - 1): +    a, b = list(map(int, readline().split())) +    lb = 1 << i +    graph[a].append((lb, b)) +    graph[b].append((lb, a)) +M = int(readline()) -def dfs(s, t): +def get_path(U, V): -    q = [(s, 0)] +    q = [(U, 0)] -        if v == t: +        if v == V: -n = int(eval(input())) -graph = [[] for _ in range(n + 1)] -for i in range(n - 1): -    a, b = list(map(int, input().split())) -    lb = 1 << i -    graph[a].append((lb, b)) -    graph[b].append((lb, a)) -conditions = [] -m = int(eval(input())) -for i in range(m): -    u, v = list(map(int, input().split())) -    conditions.append(dfs(u, v)) -link_conditions = [ -    int("".join(b), 2) -    for b in zip(*list(map(("{:0" + str(n - 1) + "b}").format, conditions))) -] -dp = defaultdict(int) -dp[0] = 1 -for lc in link_conditions: -    for fulfilled, pattern in list(dp.items()): -        dp[fulfilled | lc] += pattern -print((dp[(1 << m) - 1])) +condition_path = [] +for i in range(M): +    u, v = list(map(int, readline().split())) +    condition_path.append(get_path(u, v)) + + +def popcnt(n): +    c = (n & 0x5555555555555555) + ((n >> 1) & 0x5555555555555555) +    c = (c & 0x3333333333333333) + ((c >> 2) & 0x3333333333333333) +    c = (c & 0x0F0F0F0F0F0F0F0F) + ((c >> 4) & 0x0F0F0F0F0F0F0F0F) +    c = (c & 0x00FF00FF00FF00FF) + ((c >> 8) & 0x00FF00FF00FF00FF) +    c = (c & 0x0000FFFF0000FFFF) + ((c >> 16) & 0x0000FFFF0000FFFF) +    c = (c & 0x00000000FFFFFFFF) + ((c >> 32) & 0x00000000FFFFFFFF) +    return c + + +sgn = np.where(popcnt(np.arange(1 << M)) % 2, -1, 1) +S = np.zeros(1 << M, np.int64) +for i in range(M): +    S[1 << i : 1 << (i + 1)] = S[: 1 << i] | condition_path[i] +n_edges = popcnt(S) +x = 1 << (N - 1 - n_edges) +answer = np.sum(x * sgn) +print(answer)