#include<iostream>
#include<algorithm>
#include <iostream> 
#include <algorithm> 
#include<string>
#include<queue>
#include<utility>
#include<fstream>
#include<queue>
#include<set>
#include<stack>
#include<bits/stdc++.h>
#define ll long long int
#define ull unsigned long long int
#define I(a) scanf("%d",&a)
#define I2(a,b) scanf("%d%d",&a,&b)
#define I3(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define L(a) scanf("%lld",&a)
#define L2(a,b) scanf("%lld%lld",&a,&b)
#define L3(a,b,c) scanf("%lld%lld%lld",&a,&b,&c)
#define PI(a) printf("%d",a)
#define PL(a) printf("%lld",a)
#define PT(t) printf("Case %d: ",t)
#define PB push_back
#define x first
#define y second
#define xx first.first
#define xy first.second
#define yx second.first
#define yy second.second
#define SC scanf
#define PC printf
#define NL printf("\n")
#define SET(a) memset(a,0,sizeof a)
#define SETR(a) memset(a,-1,sizeof a)
#define SZ(a) ((int)a.size())-1
#define f(i,a,b) for(int i=a;i<=b; i++)
#define fr(i,a,b) for(int i=a;i<=b; i++)
#define frr(i,a,b) for(int i=a;i>=b; i--)
#define frv(i,a)  for(int i=0;i<a.size();i++)
#define pi 2.0*acos(0.0)
#define R(a) freopen(a, "r", stdin);
#define W(a) freopen(a, "w", stdout);
#define CB(x) __builtin_popcount(x)
#define STN(a) stringtonumber<ll>(a)
#define lol printf("BUG\n")
#define Endl "\n"
#define mk make_pair
using namespace std;
template <class T> inline T BM(T p, T e, T M)
{
    ll ret = 1;
    for(; e > 0; e >>= 1)
    {
        if(e & 1) ret = (ret * p) % M;
        p = (p * p) % M;
    }
    return (T)ret;
}
template <class T> inline T gcd(T a, T b)
{
    if(b == 0)return a;
    return gcd(b, a % b);
}
template <class T> inline T mdINV(T a, T M)
{
    return BM(a, M - 2, M);
}
template <class T> inline T PW(T p, T e)
{
    ll ret = 1;
    for(; e > 0; e >>= 1)
    {
        if(e & 1) ret = (ret * p);
        p = (p * p);
    }
    return (T)ret;
}
 
 
template <class T>bool ISLEFT(T a, T b, T c)
{
    if(((a.xx - b.xx) * (b.yy - c.yy) - (b.xx - c.xx) * (a.yy - b.yy)) < 0.0)return 1;  //Uporer dike //A,b,c, x okkher ordera sorted
    else return 0;
}
 
 
typedef pair<int,int >P;
//////////////////////////
/////////////////////////
//#include<bits/stdc++.h>
using namespace std;
#define Base1   101LL
#define Base2   10000079LL
#define Base3   10000103LL
#define MOD1    1000000007LL
#define MOD2    1000000009LL
#define MOD3    1000000021LL
#define mx 100000//Number of charter of main string
#define mx1 25000// Number off character of total charcater
#define mx2 500// Number of pattern and number of ch of each pattern


int ar[100+2][2];
int n;
int m;
int mu[100];
ll DP[51][(1<<20)+2]; 
ll dp(int i, int musk){

    if(i == n){
        if( musk == (1<<m)-1)return 1;
        return 0;
    }
    ll &ret = DP[i][musk];
    if(ret != -1)return ret;
    ret = 0;
    ret += dp(i+1, musk);
    //cout<<mu[i]<<endl;
    ret += dp(i+1, musk | mu[i]);
    return ret;
}
vector<int>v[100+2];
vector<int> re(int s, int r){
        int vis[n+2];
        SETR(vis);
        queue<int>q;
        q.push(s);
        vis[s] = 1;
        vector<int>ans;
        while(!q.empty()){
            int f = q.front();
            ans.PB(f);
            q.pop();
            for(int j = 0;j<v[f].size();j++){
                int x = v[f][j];
                if(vis[x]== -1 && x!= r){
                    vis[x] = 1;
                    q.push(x);
                }
            }
        }
        return ans;

}

int main(){
    I(n);

    for(int i = 1;i < n; i++ ){
        int x,y;
        I2(x,y);
        ar[i][0] = x;
        ar[i][1] = y;
        v[x].PB(y);
        v[y].PB(x);
    }

    I(m);
    pair<int,int>br[m+2];

    for(int i =0;i<m;i++){
        cin>>br[i].x>>br[i].y;
    }

    for(int i = 1; i < n;i++){
        vector<int> a = re(ar[i][0], ar[i][1]);
        vector<int>b = re(ar[i][1], ar[i][0]);
        for(int  j = 0;j <a.size();j++){
            for(int k = 0;k<b.size();k++){
                int x = a[j];
                int y = b[k];
                for(int l = 0;l<m;l++){
                    if((br[l].x == x && br[l].y == y )||(br[l].y == x && br[l].x == y)){
                        mu[i] = (mu[i] | (1<<l));
                    }
                }
            }
        }
    }
    SETR(DP);
    ll ans = dp(1, 0);
    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 418048