import sys

read = sys.stdin.buffer.read

readline = sys.stdin.buffer.readline

readlines = sys.stdin.buffer.readlines

from collections import deque



n = int(readline())

g = [[] * n for i in range(n)]

for i in range(n-1):

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

  u -= 1

  v -= 1

  g[u].append(v)

  g[v].append(u)

  

m = int(readline())

c = []

for i in range(m):

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

  u -= 1

  v -= 1  

  que = deque()

  que.append((u,set()))

  chk = [False]*n

  chk[u] = True

  while que:

      now,L = que.popleft()

      if now == v:

        c.append(L)

        break

      for i in g[now]:

          if not chk[i]:

            chk[i] = True

            mi = min(now,i)

            ma = max(now,i)

            que.append((i,L|{mi*100+ma}))

                     

import itertools

#print(c)

ans = 1<<(n-1)

for i in range(1,m+1):

  for j in itertools.combinations(c,i):

    K = set()

    for k in j:

      K |= k

    l = len(K)

    ans += pow(-1,i)*pow(2,n-1-l)

    

print(ans)
import sys

read = sys.stdin.buffer.read

readline = sys.stdin.buffer.readline

readlines = sys.stdin.buffer.readlines

from collections import deque,defaultdict



def all_bit_count(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

  

n = int(readline())

d = defaultdict(int)

cnt = 1



g = [[] * n for i in range(n)]

for i in range(n-1):

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

  u -= 1

  v -= 1

  g[u].append(v)

  g[v].append(u)



m = int(readline())

c = []

for i in range(m):

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

  u -= 1

  v -= 1  

  que = deque()

  que.append((u,0))

  chk = [False]*n

  chk[u] = True

  while que:

      now,L = que.popleft()

      if now == v:

        c.append(L)

        break

      for i in g[now]:

          if not chk[i]:

            chk[i] = True

            mi = min(now,i)

            ma = max(now,i)

            mm = mi*100+ma

            if d[mm] == 0:

              d[mm] = cnt

              cnt += 1

            que.append((i,L|(1<<d[mm])))

                     

import itertools

ans = 1<<(n-1)

for i in range(1,m+1):

  for j in itertools.combinations(c,i):

    K = 0

    for k in j:

      K |= k

    l = all_bit_count(K)

    ans += pow(-1,i)*pow(2,n-1-l)

    

print(ans)
import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
from collections import deque

n = int(readline())
g = [[] * n for i in range(n)]
for i in range(n - 1):
    u, v = list(map(int, readline().split()))
    u -= 1
    v -= 1
    g[u].append(v)
    g[v].append(u)
m = int(readline())
c = []
for i in range(m):
    u, v = list(map(int, readline().split()))
    u -= 1
    v -= 1
    que = deque()
    que.append((u, set()))
    chk = [False] * n
    chk[u] = True
    while que:
        now, L = que.popleft()
        if now == v:
            c.append(L)
            break
        for i in g[now]:
            if not chk[i]:
                chk[i] = True
                mi = min(now, i)
                ma = max(now, i)
                que.append((i, L | {mi * 100 + ma}))
import itertools

# print(c)
ans = 1 << (n - 1)
for i in range(1, m + 1):
    for j in itertools.combinations(c, i):
        K = set()
        for k in j:
            K |= k
        l = len(K)
        ans += pow(-1, i) * pow(2, n - 1 - l)
print(ans)

import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
from collections import deque, defaultdict


def all_bit_count(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


n = int(readline())
d = defaultdict(int)
cnt = 1
g = [[] * n for i in range(n)]
for i in range(n - 1):
    u, v = list(map(int, readline().split()))
    u -= 1
    v -= 1
    g[u].append(v)
    g[v].append(u)
m = int(readline())
c = []
for i in range(m):
    u, v = list(map(int, readline().split()))
    u -= 1
    v -= 1
    que = deque()
    que.append((u, 0))
    chk = [False] * n
    chk[u] = True
    while que:
        now, L = que.popleft()
        if now == v:
            c.append(L)
            break
        for i in g[now]:
            if not chk[i]:
                chk[i] = True
                mi = min(now, i)
                ma = max(now, i)
                mm = mi * 100 + ma
                if d[mm] == 0:
                    d[mm] = cnt
                    cnt += 1
                que.append((i, L | (1 << d[mm])))
import itertools

ans = 1 << (n - 1)
for i in range(1, m + 1):
    for j in itertools.combinations(c, i):
        K = 0
        for k in j:
            K |= k
        l = all_bit_count(K)
        ans += pow(-1, i) * pow(2, n - 1 - l)
print(ans)

-from collections import deque +from collections import deque, defaultdict + + +def all_bit_count(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 + +d = defaultdict(int) +cnt = 1 -    que.append((u, set())) +    que.append((u, 0)) -                que.append((i, L | {mi * 100 + ma})) +                mm = mi * 100 + ma +                if d[mm] == 0: +                    d[mm] = cnt +                    cnt += 1 +                que.append((i, L | (1 << d[mm]))) -# print(c) -        K = set() +        K = 0 -        l = len(K) +        l = all_bit_count(K)