import sys

input = lambda : sys.stdin.readline().rstrip()

sys.setrecursionlimit(max(1000, 10**9))

write = lambda x: sys.stdout.write(x+"\n")





from collections import defaultdict

n = int(eval(input()))

ns = defaultdict(set)

uv2e = {}

for i in range(n-1):

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

    ns[u-1].add(v-1)

    ns[v-1].add(u-1)

    uv2e[u-1,v-1] = i

    uv2e[v-1,u-1] = i

    

m = int(eval(input()))

uvs = [None]*m

for i in range(m):

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

    u -= 1

    v -= 1

    uvs[i] = (u,v)

    

from queue import deque    

def bfs(start):

    q = deque([start])

    seen = [None] * n

    seen[start] = 0

    while q:

        u = q.pop()

        d = seen[u]

        for v in ns[u]:

            if seen[v] is None:

                seen[v] = u

                q.appendleft(v)

    return seen



paths = [None]*m

for i,(u,v) in enumerate(uvs):

    seen = bfs(u)

    ss = set()

    z = v

    while z!=u:

        z1 = seen[z]

        ss.add(uv2e[z,z1])

        z = z1

    paths[i] = ss

    

ans = 0

def dfs(l, s):

    if len(l)==m:

        global ans

        val = pow(2, n-1-len(s)) * pow(-1, sum(l))

        ans += val

#         print(val, sum(l), ans)

        return

    dfs(l + [0], s)

    

    i = len(l)

    p = paths[i]

    dfs(l + [1], s|p)

    

dfs([], set())

# ans = pow(2,n-1) - ans

print(ans)
import sys

input = lambda : sys.stdin.readline().rstrip()

sys.setrecursionlimit(max(1000, 10**9))

write = lambda x: sys.stdout.write(x+"\n")





from collections import defaultdict

n = int(eval(input()))

ns = defaultdict(set)

uv2e = {}

for i in range(n-1):

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

    ns[u-1].add(v-1)

    ns[v-1].add(u-1)

    uv2e[u-1,v-1] = i

    uv2e[v-1,u-1] = i

    

m = int(eval(input()))

uvs = [None]*m

for i in range(m):

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

    u -= 1

    v -= 1

    uvs[i] = (u,v)

    

from queue import deque    

def bfs(start):

    q = deque([start])

    seen = [None] * n

    seen[start] = 0

    while q:

        u = q.pop()

        d = seen[u]

        for v in ns[u]:

            if seen[v] is None:

                seen[v] = u

                q.appendleft(v)

    return seen



paths = [None]*m

for i,(u,v) in enumerate(uvs):

    seen = bfs(u)

    ss = set()

    z = v

    while z!=u:

        z1 = seen[z]

        ss.add(uv2e[z,z1])

        z = z1

    paths[i] = ss

    

ans = 0

def dfs(l, s):

    if len(l)==m:

        global ans

        val = pow(2, n-1-len(s)) * pow(-1, sum(l))

        ans += val

#         print(val, sum(l), ans)

        return

    l.append(0)

    dfs(l, s)

    l.pop()

    

    i = len(l)

    p = paths[i]

    l.append(1)

    dfs(l, s|p)

    l.pop()

    

dfs([], set())

# ans = pow(2,n-1) - ans

print(ans)
import sys

input = lambda: sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x + "\n")
from collections import defaultdict

n = int(eval(input()))
ns = defaultdict(set)
uv2e = {}
for i in range(n - 1):
    u, v = list(map(int, input().split()))
    ns[u - 1].add(v - 1)
    ns[v - 1].add(u - 1)
    uv2e[u - 1, v - 1] = i
    uv2e[v - 1, u - 1] = i
m = int(eval(input()))
uvs = [None] * m
for i in range(m):
    u, v = list(map(int, input().split()))
    u -= 1
    v -= 1
    uvs[i] = (u, v)
from queue import deque


def bfs(start):
    q = deque([start])
    seen = [None] * n
    seen[start] = 0
    while q:
        u = q.pop()
        d = seen[u]
        for v in ns[u]:
            if seen[v] is None:
                seen[v] = u
                q.appendleft(v)
    return seen


paths = [None] * m
for i, (u, v) in enumerate(uvs):
    seen = bfs(u)
    ss = set()
    z = v
    while z != u:
        z1 = seen[z]
        ss.add(uv2e[z, z1])
        z = z1
    paths[i] = ss
ans = 0


def dfs(l, s):
    if len(l) == m:
        global ans
        val = pow(2, n - 1 - len(s)) * pow(-1, sum(l))
        ans += val
        #         print(val, sum(l), ans)
        return
    dfs(l + [0], s)
    i = len(l)
    p = paths[i]
    dfs(l + [1], s | p)


dfs([], set())
# ans = pow(2,n-1) - ans
print(ans)

import sys

input = lambda: sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x + "\n")
from collections import defaultdict

n = int(eval(input()))
ns = defaultdict(set)
uv2e = {}
for i in range(n - 1):
    u, v = list(map(int, input().split()))
    ns[u - 1].add(v - 1)
    ns[v - 1].add(u - 1)
    uv2e[u - 1, v - 1] = i
    uv2e[v - 1, u - 1] = i
m = int(eval(input()))
uvs = [None] * m
for i in range(m):
    u, v = list(map(int, input().split()))
    u -= 1
    v -= 1
    uvs[i] = (u, v)
from queue import deque


def bfs(start):
    q = deque([start])
    seen = [None] * n
    seen[start] = 0
    while q:
        u = q.pop()
        d = seen[u]
        for v in ns[u]:
            if seen[v] is None:
                seen[v] = u
                q.appendleft(v)
    return seen


paths = [None] * m
for i, (u, v) in enumerate(uvs):
    seen = bfs(u)
    ss = set()
    z = v
    while z != u:
        z1 = seen[z]
        ss.add(uv2e[z, z1])
        z = z1
    paths[i] = ss
ans = 0


def dfs(l, s):
    if len(l) == m:
        global ans
        val = pow(2, n - 1 - len(s)) * pow(-1, sum(l))
        ans += val
        #         print(val, sum(l), ans)
        return
    l.append(0)
    dfs(l, s)
    l.pop()
    i = len(l)
    p = paths[i]
    l.append(1)
    dfs(l, s | p)
    l.pop()


dfs([], set())
# ans = pow(2,n-1) - ans
print(ans)

-    dfs(l + [0], s) +    l.append(0) +    dfs(l, s) +    l.pop() -    dfs(l + [1], s | p) +    l.append(1) +    dfs(l, s | p) +    l.pop()