#include <iostream>
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cstring>
#include <deque>
#include <functional>
#include <initializer_list>
#include <math.h>
#include <map>
#include <random>
#include <set>
#include <stack>
#include <tuple>
#include <queue>
#include <vector>

#define FOR(i, a, b) for(int (i) = (a); (i) < (b); ++(i))
#define rFOR(i, a, b) for(int (i) = (b); (i) >= (a); --(i))
#define REP(i, n) FOR(i, 0, n)
#define rREP(i, n) rFOR(i, 0, (n-1))
#define SORT(A) std::sort((A).begin(), (A).end())
#define ALL(A) (A).begin(), (A).end()
// 座標圧縮 (for vector) : ソートしてから使うのが一般的 ; SORT(A) => COORDINATE_COMPRESSION(A)
#define COORDINATE_COMPRESSION(A) (A).erase(unique((A).begin(),(A).end()),(A).end())

using lli = long long int;
using pii = std::pair<int, int>;

// グリッド上の縦横移動
constexpr std::array<std::pair<int, int>, 4> dxdy = {
    std::pair<int, int>( 1,  0),
    std::pair<int, int>(-1,  0),
    std::pair<int, int>( 0,  1),
    std::pair<int, int>( 0, -1)
};

void VintOut(std::vector<int>& A){
    const int n = A.size();
    if(n == 0){putchar('\n'); return;}
    printf("%d", A[0]);
    for(int i = 1; i < n; ++i) printf(" %d", A[i]);
    putchar('\n');
}
void VintOut(std::vector<long long int>& A){
    const int n = A.size();
    if(n == 0){ putchar('\n'); return;}
    printf("%lld", A[0]);
    for(int i = 1; i < n; ++i) printf(" %lld", A[i]);
    putchar('\n');
}

template <typename T>
inline bool chmin(T& a, T b){
    if(b < a){ a = b; return true;}
    return false;
}

template <typename T>
inline bool chmax(T& a, T b){
    if(a < b){ a = b; return true;}
    return false;
}

inline bool isIn(int x, int y, int H, int W){
    return 0 <= x and x < H and 0 <= y and y < W;
}
inline bool bitUP(int state, int k){ return (state >> k) & 1; }
inline bool bitUP(long long int state, int k){ return (state >> k) & 1;}

// z-algorithm
template <class T> std::vector<int> z_algorithm(const T &str) {
    const int n = str.size();
    std::vector<int> resOfCP(n); resOfCP[0] = n;
    int i = 1, j = 0;
    while (i < n) {
        while (i + j < n and str[j] == str[i + j]) ++j;
        resOfCP[i] = j;
        if (j == 0) { ++i; continue;}
        int k = 1;
        while (i + k < n and k + resOfCP[k] < j) resOfCP[i + k] = resOfCP[k], ++k;
        i += k; j -= k;
    }
    return resOfCP;
}


// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

constexpr int inf = 1e9 + 334 + 810 + 1919;
constexpr int N = 100;
std::array<std::array<int, N + 1>, N + 1> Num;
std::vector<std::vector<int>> Edge; // 枝
std::vector<std::vector<bool>> R; // 制約

std::vector<std::vector<lli>> DP;


int main(void){
    // 入力
    int n; scanf("%d", &n);
    
    Edge.assign(n, std::vector<int>(0));
    // 枝の入力受け取り : 1-indexedで入力がくると想定
    for(int _ = 1; _ < n; ++_){
        int vx, uy; scanf("%d%d", &vx, &uy); vx--; uy--;
        Edge[vx].push_back(uy); Edge[uy].push_back(vx);

        Num[vx][uy] = _ - 1; Num[uy][vx] = _ - 1;
    }

    std::vector<int> Dist(n);


    int m; scanf("%d", &m); R.assign(m, std::vector<bool>(n, false));

    REP(i, m){
        int u, v; scanf("%d%d", &u, &v); u--; v--;
        std::fill(Dist.begin(), Dist.end(), inf);
        std::queue<int> Q; Dist[u] = 0; Q.push(u);

        while(not Q.empty()){
            int nv = Q.front(); Q.pop();
            for(int nnv : Edge[nv]) if(Dist[nnv] == inf){
                Dist[nnv] = Dist[nv] + 1;
                Q.push(nnv);
            }
        }

        while(Dist[v] > 0){
            int nv = v;
            for(int nnv : Edge[v]) if(Dist[nnv] < Dist[v]){nv = nnv; break;}
            int num = Num[v][nv];
            R[i][num] = true;
            v = nv;
        }
    }

    // DP[i][j] := i 個の枝をみて, 状態が j となるような場合
    int State = 1 << m;
    DP.assign(n, std::vector<lli>(State, 0));
    DP[0][0] = 1;

    REP(i, n - 1){
        int addr = 0;
        // j 番目の制約があることによって満たすかどうか
        REP(j, m) if(R[j][i]) addr |= (1 << j);
        for(int state = 0; state < State; ++state){
            DP[i + 1][state] += DP[i][state];
            int nstate = state; nstate |= addr;
            DP[i + 1][nstate] += DP[i][state];
        }
    }

    
    printf("%lld\n", DP[n-1][State - 1]);










    
    
    return 0;
}

Measured memory_bytes: 418304