#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
#define ll          long long
#define pb          push_back
#define INF         9223372036854775807
#define    endl        '\n'
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define hell        1000000007
#define rep(i,a,b)    for(ll int i=a;i<b;i++)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define lower(u)    transform(u.begin(), u.end(), u.begin(), ::tolower);//convert string u to lowercase;
#define upper(u)    transform(u.begin(), u.end(), u.begin(), ::toupper);
using namespace std;

using namespace __gnu_pbds; 
  
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
#define N  1005

ll P[N][30];            
ll T[N];                            
ll L[N];                     
vector<ll> adj[N];
bool vis[N];
ll n;
map<pii,ll>edge;
map<ll,pii>edge2;
void precal(ll node,ll parent,ll distance)
{
    vis[node]=1;
    T[node]=parent;
    L[node]=distance;
    for(auto u:adj[node])
    {
        if(!vis[u])
        {
            precal(u,node,distance+1);
        }
    }
}
void process()
{
    ll i,j; 
    for(i=0;i<N;i++)
    for(j=0;1<<j<N;j++)
        P[i][j]=-1; 
    for (i=0;i<N;i++)
        P[i][0]=T[i]; 
    for(j=1;1<<j<N;j++)
    for(i=0;i<N;i++)
        if(P[i][j-1]!=-1)
            P[i][j]=P[P[i][j-1]][j-1];
}
ll query(ll p,ll q)
{
    ll tmp,log,i; 
    if(L[p]<L[q])
        tmp=p,p=q,q=tmp; 
    for(log=1;1<<log<=L[p];log++);
    log--; 
    for(i=log;i>=0;i--)
        if(L[p]-(1<<i)>=L[q])
            p=P[p][i]; 
    if(p==q)
        return p;
    for(i=log;i>=0;i--)
        if(P[p][i]!=-1&&P[p][i]!=P[q][i])
            p=P[p][i],q=P[q][i]; 
 
    return T[p];
}
ll expo(ll base,ll exponent,ll mod){
    ll ans=1;
    while(exponent!=0){
        if(exponent&1) ans=(ans*base);
        base=(base*base);
        exponent>>=1;
    }
    return ans;
}
ll popcount(ll x)
{
    ll ans=0;
    while(x!=0)
    {
        if(x&1)
            ans++;
        x>>=1;
    }
    return ans;
}
void solve()
{
    
    
    ll x,y,z,num=0;
    cin>>n;
    ll pow2[51];
    pow2[0]=1;
    rep(i,1,51)
    {
        pow2[i]=2ll*pow2[i-1];
    }
    rep(i,0,n-1)
    {
        cin>>x>>y;
        adj[x].pb(y);
        adj[y].pb(x);
        edge[{min(x,y),max(x,y)}]=i;
    }
    // for(auto u:edge)
    // {
    //     cout<<u.F.F<<" "<<u.F.S<<" "<<u.S<<endl;
    // }
    precal(1,0,0);
    process();
    ll q;
    vi v;
    cin>>q;
    rep(i,0,q)
    {
        num=0;
        cin>>x>>y;
        z=query(x,y);
        // cout<<x<<" "<<y<<" "<<z<<endl;
        if(x!=z)
        {
            while(x!=z)
            {
                // cout<<"X "<<edge[{min(x,T[x]),max(x,T[x])}]<<endl;
                num+=(1ll<<(edge[{min(x,T[x]),max(x,T[x])}]));
                x=T[x];
            }
        }
        if(y!=z)
        {
            while(y!=z)
            {
                // cout<<"Y "<<edge[{min(y,T[y]),max(y,T[y])}]<<endl;
                num+=(1ll<<(edge[{min(y,T[y]),max(y,T[y])}]));
                // 
                // cout<<num<<" y "<<edge[{min(y,T[y]),max(y,T[y])}]<<endl;
                y=T[y];
            }
        }
        // cout<<num<<endl;
        v.pb(num);
    }
    ll ans=0;
    for(ll i=1;i<(1ll<<q);i++)
    {
        num=0;
        rep(j,0,q)
        {
            if((i>>j)&1ll)
            {
                num|=v[j];
            }
        }
        x=popcount(num);
        y=popcount(i);
        // cout<<x<<" pop "<<y<<endl;
        if(y%2)
        ans=(ans+expo(2,n-1-x,hell));
        else
        {
            ans=(ans-expo(2,n-1-x,hell));
        }
    }
    
    ll finres=expo(2,n-1,hell);
    finres=(finres-ans);
    cout<<finres<<endl;
    // for(auto u:edge)
    // {
    //     cout<<u.F.F<<" "<<u.F.S<<" "<<u.S<<endl;
    // }
    // for(auto u:v)
    // {
    //     cout<<num<<endl;
    // }

}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    int TESTS=1;
//    cin>>TESTS;
    while(TESTS--)
    {
        solve();
    }
    return 0;
}

Measured memory_bytes: 3932