import sys

def main():

    input = sys.stdin.readline

    N = int(eval(input()))

    E = [[] for _ in range(N)]

    for i in range(N-1):

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

        a, b = a-1, b-1

        E[a].append((b,i))

        E[b].append((a,i))

    

    def dfs(s, g):

        par = [(-1,-1)] * N

        par[s] = (s,-1)

        stack = [s]

        while stack:

            v = stack.pop()

            for to, i in E[v]:

                if par[to][0] >= 0: continue

                par[to] = (v, i)

                if to == g: break

                stack.append(to)

        r = 0

        v = g

        while v != s:

            v, i = par[v]

            r |= 1 << i

        return r

    

    M = int(eval(input()))

    path = [0] * M

    for i in range(M):

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

        u, v = u-1, v-1

        path[i] = dfs(u, v)



    def calc(s): return 1<<(N-1-bin(s).count('1'))



    i_ans = 0

    for p in range(1, 1<<M):

        is_odd = 0

        s = 0

        for i in range(M):

            if p&1:

                s |= path[i]

                is_odd ^= 1

            p >>= 1

        if is_odd: i_ans += calc(s)

        else: i_ans -= calc(s)



    print(((1<<(N-1)) - i_ans))



if __name__ == '__main__':

    main()
import sys

def main():

    input = sys.stdin.readline

    N = int(eval(input()))

    E = [[] for _ in range(N)]

    for i in range(N-1):

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

        a, b = a-1, b-1

        E[a].append((b,i))

        E[b].append((a,i))

    

    def dfs(s, g):

        par = [(-1,-1)] * N

        par[s] = (s,-1)

        stack = [s]

        while stack:

            v = stack.pop()

            for to, i in E[v]:

                if par[to][0] >= 0: continue

                par[to] = (v, i)

                if to == g: break

                stack.append(to)

        r = 0

        v = g

        while v != s:

            v, i = par[v]

            r |= 1 << i

        return r

    

    M = int(eval(input()))

    path = [0] * M

    for i in range(M):

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

        u, v = u-1, v-1

        path[i] = dfs(u, v)



    def calc(s): return 1<<(N-1-popcount(s))



    i_ans = 0

    for p in range(1, 1<<M):

        is_odd = 0

        s = 0

        for i in range(M):

            if p&1:

                s |= path[i]

                is_odd ^= 1

            p >>= 1

        if is_odd: i_ans += calc(s)

        else: i_ans -= calc(s)



    print(((1<<(N-1)) - i_ans))



def popcount(x):

    x = (x & 0x5555555555555555) + (x >> 1 & 0x5555555555555555);

    x = (x & 0x3333333333333333) + (x >> 2 & 0x3333333333333333);

    x = (x & 0x0f0f0f0f0f0f0f0f) + (x >> 4 & 0x0f0f0f0f0f0f0f0f);

    x = (x & 0x00ff00ff00ff00ff) + (x >> 8 & 0x00ff00ff00ff00ff);

    x = (x & 0x0000ffff0000ffff) + (x >>16 & 0x0000ffff0000ffff);

    return (x & 0x00000000ffffffff) + (x >>32 & 0x00000000ffffffff);



if __name__ == '__main__':

    main()
import sys


def main():
    input = sys.stdin.readline
    N = int(eval(input()))
    E = [[] for _ in range(N)]
    for i in range(N - 1):
        a, b = list(map(int, input().split()))
        a, b = a - 1, b - 1
        E[a].append((b, i))
        E[b].append((a, i))

    def dfs(s, g):
        par = [(-1, -1)] * N
        par[s] = (s, -1)
        stack = [s]
        while stack:
            v = stack.pop()
            for to, i in E[v]:
                if par[to][0] >= 0:
                    continue
                par[to] = (v, i)
                if to == g:
                    break
                stack.append(to)
        r = 0
        v = g
        while v != s:
            v, i = par[v]
            r |= 1 << i
        return r

    M = int(eval(input()))
    path = [0] * M
    for i in range(M):
        u, v = list(map(int, input().split()))
        u, v = u - 1, v - 1
        path[i] = dfs(u, v)

    def calc(s):
        return 1 << (N - 1 - bin(s).count("1"))

    i_ans = 0
    for p in range(1, 1 << M):
        is_odd = 0
        s = 0
        for i in range(M):
            if p & 1:
                s |= path[i]
                is_odd ^= 1
            p >>= 1
        if is_odd:
            i_ans += calc(s)
        else:
            i_ans -= calc(s)
    print(((1 << (N - 1)) - i_ans))


if __name__ == "__main__":
    main()

import sys


def main():
    input = sys.stdin.readline
    N = int(eval(input()))
    E = [[] for _ in range(N)]
    for i in range(N - 1):
        a, b = list(map(int, input().split()))
        a, b = a - 1, b - 1
        E[a].append((b, i))
        E[b].append((a, i))

    def dfs(s, g):
        par = [(-1, -1)] * N
        par[s] = (s, -1)
        stack = [s]
        while stack:
            v = stack.pop()
            for to, i in E[v]:
                if par[to][0] >= 0:
                    continue
                par[to] = (v, i)
                if to == g:
                    break
                stack.append(to)
        r = 0
        v = g
        while v != s:
            v, i = par[v]
            r |= 1 << i
        return r

    M = int(eval(input()))
    path = [0] * M
    for i in range(M):
        u, v = list(map(int, input().split()))
        u, v = u - 1, v - 1
        path[i] = dfs(u, v)

    def calc(s):
        return 1 << (N - 1 - popcount(s))

    i_ans = 0
    for p in range(1, 1 << M):
        is_odd = 0
        s = 0
        for i in range(M):
            if p & 1:
                s |= path[i]
                is_odd ^= 1
            p >>= 1
        if is_odd:
            i_ans += calc(s)
        else:
            i_ans -= calc(s)
    print(((1 << (N - 1)) - i_ans))


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


if __name__ == "__main__":
    main()

-        return 1 << (N - 1 - bin(s).count("1")) +        return 1 << (N - 1 - popcount(s)) +def popcount(x): +    x = (x & 0x5555555555555555) + (x >> 1 & 0x5555555555555555) +    x = (x & 0x3333333333333333) + (x >> 2 & 0x3333333333333333) +    x = (x & 0x0F0F0F0F0F0F0F0F) + (x >> 4 & 0x0F0F0F0F0F0F0F0F) +    x = (x & 0x00FF00FF00FF00FF) + (x >> 8 & 0x00FF00FF00FF00FF) +    x = (x & 0x0000FFFF0000FFFF) + (x >> 16 & 0x0000FFFF0000FFFF) +    return (x & 0x00000000FFFFFFFF) + (x >> 32 & 0x00000000FFFFFFFF) + +