#include <bits/stdc++.h>
using namespace std;
const auto start_time = std::chrono::high_resolution_clock::now();
void timecalculater(){
    #ifndef ONLINE_JUDGE
    auto end_time = std::chrono::high_resolution_clock::now();
    std::chrono::duration<double> diff = end_time-start_time;
    cerr<<"Time Taken : "<<diff.count()<<"\n";
    #endif
}
void __print(int x) {cout << x;}
void __print(long x) {cout << x;}
void __print(long long x) {cout << x;}
void __print(unsigned x) {cout << x;}
void __print(unsigned long x) {cout << x;}
void __print(unsigned long long x) {cout << x;}
void __print(float x) {cout << x;}
void __print(double x) {cout << x;}
void __print(long double x) {cout << x;}
void __print(char x) {cout << '\'' << x << '\'';}
void __print(const char *x) {cout << '\"' << x << '\"';}
void __print(const string &x) {cout << '\"' << x << '\"';}
void __print(bool x) {cout << (x ? "true" : "false");}
template<typename T, typename V>
void __print(const pair<T, V> &x) {cout << '{'; __print(x.first); cout << ','; __print(x.second); cout << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cout << '{'; for (auto &i: x) cout << (f++ ? "," : ""), __print(i); cout << "}";}
void _print() {cout << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cout << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define dbg(x...) cout << "[" << #x << "] = ["; _print(x)
#else
#define dbg(x...)
#endif
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define repA(i, a, n) for(int  i = a; i <= (n); ++i)
#define all(x) x.begin(), x.end()
#define sz(x) (int) (x).size()
#define fill(a,v) memset(a, v, sizeof(a))
#define fst first
#define snd second
#define mp make_pair
#define pb push_back
#define endl '\n'
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<long long int> vll;
typedef vector<pii> vii;
ll p=1e9+7;
const int N=2e5+5;
int main() {
    cin.sync_with_stdio(0); cin.tie(0);
    cin.exceptions(cin.failbit);
    int T=1;
    // cin>>T;
    while(T--){
        ll ans=0;
        ll n;cin>>n;
        vector<ll> g[n];
        map<pll,ll> ma;
        rep(i,n-1){
            ll u,v;cin>>u>>v;v--;u--;
            if(u>v)swap(u,v);
            g[u].pb(v);
            g[v].pb(u);
            ma[{u,v}]=i;
        }
        ll  m;cin>>m;
        ll res[m]={0};
        rep(i,m){
            ll u,v;cin>>u>>v;u--;v--;
            queue<ll> q;
            ll par[n]={0};
            par[u]=-1;
            q.push(u);
            while(!q.empty()){
                ll r=q.front();
                q.pop();
                for(auto j: g[r]){
                    if(j!=par[r]){
                        par[j]=r;
                        q.push(j);
                    }
                }
            }
            while(par[v]!=-1){
                ll p=par[v];
                ll ind=ma[{min(p,v),max(p,v)}];
                res[i]=res[i]|((1ll)<<ind);
                v=p;
            }
        }
        ll temp=0;ans=(((1ll)<<(n-(1ll))));
        for(ll i=(1ll);i<((1ll)<<m);i++){
            ll x=__builtin_popcountll(i);
            ll val=0;
            ll s=0;
            rep(j,m){
                if(i&((1ll)<<j)){
                    s=s|(res[j]);     
                }
            }
            ll u=__builtin_popcountll(s);
            val=(1ll)<<((n-(1ll)-u));
            if(x%2==0){
                temp-=val;
            }
            else{
                temp+=val;
            }
            // dbg(val);
        }
        cout<<ans-temp;
    }   
    timecalculater();
    return 0;   
} 

Measured memory_bytes: 256