#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
void *wmem;
char memarr[96000000];
template<class T> inline void walloc1d(T **arr, int x, void **mem = &wmem){
  static int skip[16] = {0, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1};
  (*mem) = (void*)( ((char*)(*mem)) + skip[((unsigned long long)(*mem)) & 15] );
  (*arr)=(T*)(*mem);
  (*mem)=((*arr)+x);
}
inline void rd(int &x){
  int k;
  int m=0;
  x=0;
  for(;;){
    k = getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
inline void wt_L(char a){
  putchar_unlocked(a);
}
inline void wt_L(long long x){
  int s=0;
  int m=0;
  char f[20];
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    putchar_unlocked('-');
  }
  while(s--){
    putchar_unlocked(f[s]+'0');
  }
}
inline int BIT_popcount_L(const int x){
  return __builtin_popcount(x);
}
inline int BIT_popcount_L(const long long x){
  return __builtin_popcountll(x);
}
struct graph{
  int N;
  int *es;
  int **edge;
  void setEdge(int N__, int M, int A[], int B[], void **mem = &wmem){
    int i;
    N = N__;
    walloc1d(&es, N, mem);
    walloc1d(&edge, N, mem);
    for(i=(0);i<(N);i++){
      es[i] = 0;
    }
    for(i=(0);i<(M);i++){
      es[A[i]]++;
      es[B[i]]++;
    }
    for(i=(0);i<(N);i++){
      walloc1d(&edge[i], es[i], mem);
    }
    for(i=(0);i<(N);i++){
      es[i] = 0;
    }
    for(i=(0);i<(M);i++){
      edge[A[i]][es[A[i]]++] = B[i];
      edge[B[i]][es[B[i]]++] = A[i];
    }
  }
  int shortestPath(const int s, const int t, int res[], void *mem=wmem){
    int i;
    int j;
    int k;
    int *q;
    int qs = 0;
    int qe = 0;
    int *b;
    walloc1d(&b, N, &mem);
    walloc1d(&q, N, &mem);
    for(i=(0);i<(N);i++){
      b[i] = -1;
    }
    b[s] = -2;
    q[qe++] = s;
    while(qe > qs){
      i = q[qs++];
      for(j=(0);j<(es[i]);j++){
        k = edge[i][j];
        if(b[k]!=-1){
          continue;
        }
        b[k] = i;
        q[qe++] = k;
      }
      if(b[t]!=-1){
        break;
      }
    }
    if(b[t]==-1){
      return -1;
    }
    k = 0;
    res[k] = i = t;
    while(i != s){
      res[++k] = (i = b[i]);
    }
    std::reverse(res, res+k+1);
    return k;
  }
}
;
int N;
int A[50];
int B[50];
int M;
int U[20];
int V[20];
graph g;
long long mask[20];
int len;
int path[51];
int main(){
  wmem = memarr;
  int i;
  int j;
  int k;
  int b1;
  int b2;
  long long mk;
  long long res = 0;
  rd(N);
  {
    int Lj4PdHRW;
    for(Lj4PdHRW=(0);Lj4PdHRW<(N-1);Lj4PdHRW++){
      rd(A[Lj4PdHRW]);A[Lj4PdHRW] += (-1);
      rd(B[Lj4PdHRW]);B[Lj4PdHRW] += (-1);
    }
  }
  rd(M);
  {
    int e98WHCEY;
    for(e98WHCEY=(0);e98WHCEY<(M);e98WHCEY++){
      rd(U[e98WHCEY]);U[e98WHCEY] += (-1);
      rd(V[e98WHCEY]);V[e98WHCEY] += (-1);
    }
  }
  g.setEdge(N,N-1,A,B);
  for(i=(0);i<(M);i++){
    len = g.shortestPath(U[i],V[i],path);
    for(j=(0);j<(len);j++){
      for(k=(0);k<(N-1);k++){
        if((A[k]==path[j] && B[k]==path[j+1]) || (B[k]==path[j] && A[k]==path[j+1])){
          mask[i] |= (1LL << k);
        }
      }
    }
  }
  for(i=(0);i<(1<<M);i++){
    b1 = mk = 0;
    for(j=(0);j<(M);j++){
      if(i & 1<<j){
        b1++;
        mk |= mask[j];
      }
    }
    b2 = N - 1 -BIT_popcount_L(mk);
    if(b1%2==0){
      res +=1LL << b2;
    }
    else{
      res -=1LL << b2;
    }
  }
  wt_L(res);
  wt_L('\n');
  return 0;
}
// cLay varsion 20200119-1

// --- original code ---
// int N, A[50], B[50], M, U[20], V[20];
// 
// graph g;
// ll mask[20];
// int len, path[51];
// 
// {
//   int i, j, k, b1, b2; ll mk;
//   ll res = 0;
//   rd(N,(A--,B--)(N-1),M,(U--,V--)(M));
//   g.setEdge(N,N-1,A,B);
//   rep(i,M){
//     len = g.shortestPath(U[i],V[i],path);
//     rep(j,len){
//       rep(k,N-1) if((A[k]==path[j] && B[k]==path[j+1]) || (B[k]==path[j] && A[k]==path[j+1])) mask[i] |= (1LL << k);
//     }
//   }
// 
//   rep(i,1<<M){
//     b1 = mk = 0;
//     rep(j,M) if(i & 1<<j){
//       b1++;
//       mk |= mask[j];
//     }
//     b2 = N - 1 - BIT_popcount(mk);
//     res if[b1%2==0,+=,-=] 1LL << b2;
//   }
// 
//   wt(res);
// }


Measured memory_bytes: 256