#include <bits/stdc++.h>
#define LOCAL
using namespace std;
template <typename A, typename B>
ostream& operator <<(ostream& out, const pair<A, B>& a) {
out << "(" << a.first << "," << a.second << ")";
return out;
}
template <typename T, size_t N>
ostream& operator <<(ostream& out, const array<T, N>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T>
ostream& operator <<(ostream& out, const vector<T>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T, class Cmp>
ostream& operator <<(ostream& out, const set<T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "}";
return out;
}
template <typename U, typename T, class Cmp>
ostream& operator <<(ostream& out, const map<U, T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& p : a) { out << (first ? "" : ", "); out << p.first << ":" << p.second; first = 0;} out << "}";
return out;
}
#ifdef LOCAL
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define trace(...) 42
#endif
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');
cerr.write(names, comma - names) << ": " << arg1 << " |";
__f(comma + 1, args...);
}
#define rep(i,n) for(int i=0; i<(n); i++)
using ll = long long;
#define int long long
using P = pair<int,int>;
//#########################################
const int mod = 1000000007;
// a^n mod を計算する
long long modpow(long long a, long long n) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a ;
        a = a * a;
        n >>= 1;
    }
    return res;
}

vector<int> ki[55];
int  es[100][100];
int id[100][100];
set<int> st;
bool dfs(int now,int last,int goal){
    if(now == goal)return true;
    for(auto next:ki[now]){
        if(next == last)continue;
        if(dfs(next,now,goal)){
            st.insert(id[now][next]);
            return true;
        }
        //trace(now,next,id[now][next],goal);
    }

    return false;
}

signed main(){
    int n;cin >> n;
    rep(i,n-1){
        int a,b;cin >> a >> b;
        a--;b--;
        ki[a].push_back(b);
        ki[b].push_back(a);
        id[a][b] = id[b][a] = i;
        
        //trace(res);
        

    }
    int m;cin >> m;
    int u[m],v[m];
    rep(i,m){
        cin >> u[i] >> v[i];
        u[i]--;v[i]--;
        st.clear();
        dfs(v[i],-1,u[i]);
        int res = 0;
        for(auto p:st){
            //trace(p);
            res |= 1ll<<p;
        }
        es[u[i]][v[i]] = es[v[i]][u[i]] = res;
    }
    int ans = 0;
    //trace(n,n-1,ans);
    rep(i,1<<m){
    
        int cnt = 0;
        int s = 0;
        rep(j,m){
            if(i>>j&1){
                //jこめの制約を満たす
                s |= es[u[j]][v[j]];
                cnt++;
            }
        }
        //trace(s,i);
        //trace(i,es.size());
        int siz = __builtin_popcountll(s);
        int cur = 1ll<<(n-1-siz);
        if(cnt%2)ans -=cur;
        else ans+= cur;

    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3716