#include <bits/stdc++.h>
using namespace std;

vector<set<int>> constraints;

long long N, M;

struct node{
    int v;
    node *ch[2];
};

unordered_map<int, unordered_map<int, node*>> dp;
unordered_map<node*, long long> cnt;
node T, F;
int node_cnt = 1;

void build(node* root, int mate, int e){
    for(int i = 0;i < 2;i++){
        int next_mate = mate;
        if(i == 1){
            for(int j = 0;j < M;j++){
                if(constraints[j].find(e) != constraints[j].end()){
                    next_mate |= (1<<j);
                }
            }
        }
        if(N - 2 == e){
            if(__builtin_popcount(next_mate) == M){
                root->ch[i] = &T;
            }else{
                root->ch[i] = &F;
            }
        }else if(dp[e + 1].find(next_mate) == dp[e + 1].end()){
            if(i == 0){
                bool f = false;
                for(int j = 0;j < M;j++){
                    if(!(mate & (1<<j)) && *constraints[j].rbegin() <= e){
                        f = true;
                        break;
                    }
                }
                if(f){
                    root->ch[i] = &F;
                    continue;
                }
            }
            node* p = new node;
            p->v = node_cnt++;
            root->ch[i] = p;
            dp[e + 1][next_mate] = p;
            build(p, next_mate, e + 1);
        }else{
            root->ch[i] = dp[e + 1][next_mate];
        }
    }
    //cout<<e<<" "<<mate<<" "<<root->v<<" "<<root->ch[0]->v<<" "<<root->ch[1]->v<<endl;
}

long long count(node* p){
    if(p == &T){
        return 1;
    }
    if(p == &F){
        return 0;
    }
    if(cnt.find(p) == cnt.end()){
        cnt[p] = count(p->ch[0]) + count(p->ch[1]);
    }
    return cnt[p];
}

void solve(std::vector<long long> a, std::vector<long long> b, std::vector<long long> u, std::vector<long long> v){
    T = node();
    T.v = -1;
    F = node();
    F.v = -2;
    vector<vector<int>> Edge_index(N, vector<int>(N));
    vector<vector<int>> Edges(N);
    for(int i = 0;i < N - 1;i++){
        Edges.at(a[i] - 1).push_back(b[i] - 1);
        Edges.at(b[i] - 1).push_back(a[i] - 1);
        Edge_index[a[i] - 1][b[i] - 1] = i;
        Edge_index[b[i] - 1][a[i] - 1] = i;
    }
    constraints = vector<set<int>>(M);
    for(int i = 0;i < M;i++){
        vector<int> restore(N, -1);
        queue<int> que; 
        que.push(u[i] - 1);
        restore[u[i] - 1] = -2;
        while(!que.empty()){
            int q = que.front();
            que.pop();
            for(auto e : Edges[q]){
                if(restore[e] == -1){
                    restore[e] = q;
                    que.push(e);
                }
            }
        }
        int q = v[i] - 1;
        while(restore[q] != -2){
            constraints[i].insert(Edge_index[q][restore[q]]);
            q = restore[q];
        }
    }
    /*
    for(auto a : constraints){
        for(auto b : a)
            cout<<b<<" ";
        cout<<endl;
    }
    */
    
    node root;
    root.v = 0;
    build(&root, 0, 0);
    //cout<<node_cnt<<endl;
    cout<<count(&root)<<endl;
}

int main(){
    scanf("%lld",&N);
    std::vector<long long> a(N-1);
    std::vector<long long> b(N-1);
    for(int i = 0 ; i < N-1 ; i++){
        scanf("%lld",&a[i]);
        scanf("%lld",&b[i]);
    }
    scanf("%lld",&M);
    std::vector<long long> u(M);
    std::vector<long long> v(M);
    for(int i = 0 ; i < M ; i++){
        scanf("%lld",&u[i]);
        scanf("%lld",&v[i]);
    }
    solve(std::move(a), std::move(b), std::move(u), std::move(v));
    return 0;
}


Measured memory_bytes: 10788