//Compete against Yourself.
#include <bits/stdc++.h>
#define _ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define sz(i) (int)(i.size())
#define F first
#define S second
#define L long double
#define P pair<int, int>
const int inf = 0x3f3f3f3f3f3f3f3LL;
const int mod = (int)1e9 + 7;
using namespace std;
#if LOCAL
#include "../../tr.h"
#else
#define tr(...)
#define endl '\n'
#endif
template<class T> void smin(T& a, T val) {if (a > val) a = val;}template<class T> void smax(T& a, T val) {if (a < val) a = val;}
const int N = 55;

struct log_lca {
    int n = 0;
    vector<int> parent, depth;
    vector<vector<int>> adj;
    vector<vector<int>> ancestor;
 
    log_lca(int _n = 0) {
        init(_n);
    }
 
    void init(int _n) {
        n = _n;
        parent.resize(n);
        depth.resize(n);
        adj.assign(n, {});
    }
 
    static int largest_bit(int x) {
        return 31 - __builtin_clz(x);
    }
 
    void add_edge(int a, int b) {
        adj[a].push_back(b);
        adj[b].push_back(a);
    }
 
    void dfs(int node, int par) {
        depth[node] = par < 0 ? 0 : depth[par] + 1;
        parent[node] = par;
 
        for (int neighbor : adj[node])
            if (neighbor != par)
                dfs(neighbor, node);
    }
 
    void build() {
        dfs(0, -1);
        ancestor.assign(largest_bit(n) + 1, vector<int>(n));
        ancestor[0] = parent;
 
        for (int k = 0; k < largest_bit(n); k++)
            for (int i = 0; i < n; i++)
                ancestor[k + 1][i] = ancestor[k][i] < 0 ? -1 : ancestor[k][ancestor[k][i]];
    }
 
    int get_lca(int a, int b) const {
        if (depth[a] > depth[b])
            swap(a, b);
 
        int difference = depth[b] - depth[a];
 
        for (int k = 0; 1 << k <= difference; k++)
            if (difference & 1 << k)
                b = ancestor[k][b];
 
        if (a == b)
            return a;
 
        assert(a != b && depth[a] == depth[b]);
 
        for (int k = largest_bit(depth[a]); k >= 0; k--)
            if (ancestor[k][a] != ancestor[k][b]) {
                a = ancestor[k][a];
                b = ancestor[k][b];
            }
 
        assert(parent[a] == parent[b]);
        return parent[a];
    }
 
    int get_dist(int a, int b) const {
        return depth[a] + depth[b] - 2 * depth[get_lca(a, b)];
    }
 
    int get_kth_ancestor(int v, int k) const {
        for (int i = 0; 1 << i <= k; i++)
            if (k & 1 << i) {
                v = ancestor[i][v];
 
                if (v < 0)
                    break;
            }
 
        return v;
    }
 
    int get_kth_node_on_path(int a, int b, int k) const {
        int anc = get_lca(a, b);
        int first_half = depth[a] - depth[anc];
        int second_half = depth[b] - depth[anc];
        assert(0 <= k && k <= first_half + second_half);
 
        if (k < first_half)
            return get_kth_ancestor(a, k);
        else
            return get_kth_ancestor(b, first_half + second_half - k);
    }
};
 
log_lca lca;
vector<int> getPath(int start, int end){
    vector<int> v;
    set<int> s;
    int lc = lca.get_lca(start, end);
 
    while(end != -1){
        if(s.find(end) == s.end()){
            v.push_back(end);
            s.insert(end);
        }
        if(end == lc)
            break;
        end = lca.parent[end];
    }
 
    vector<int> v2;
    while(start != -1){
        if(s.find(start) == s.end()){
            v2.push_back(start);
            s.insert(start);
        }
        if(start == lc)
            break;
        start = lca.parent[start];
    }
 
    reverse(v2.begin(), v2.end());
    for(auto it: v2){
        v.push_back(it);
    }
 
    return v;
}

int n;
vector<int> v[N];
vector<vector<int>> res;
vector<int> path[N][N];
map<P, int> fast;

int32_t main(){_
   
   cin>>n;

   lca.init(n);
   for (int i = 0; i+1 < n; ++i)
   {
      int x, y;
      cin >> x >> y;
      --x, --y;
      if(x > y)swap(x, y);
      fast[{x, y}] = i;
      lca.add_edge(x, y);
      v[x].push_back(y);
      v[y].push_back(x);
   }

   lca.build();
   int m;
   cin >> m;

   for (int i = 0; i < m; ++i)
   {
      int x, y;
      cin >> x >> y;
      --x, --y;
      if(x > y)swap(x, y);
      res.push_back({x, y});
      path[x][y] = (getPath(x, y));
   }
      
   long long ans = 0;
   for (int i = 0; i < (1LL << m); ++i)
   {
      vector<vector<int>> bad;
      for (int j = 0; j < m; ++j)
      {
         if(i & (1LL << j)){
            bad.push_back(res[j]);
         }
      }

      long long msk = 0;
      for(auto it: bad){
         int st = it[0], en = it[1];
         vector<int> ok = path[st][en];
         for (int i = 0; i+1 < (int)(ok.size()); ++i)
         {
            int curr = ok[i], nxt = ok[i+1];
            if(curr > nxt)swap(curr, nxt);
            int idx = fast[{curr, nxt}];
            msk |= (1LL << idx);
         }
      }

      long long rem = (n - 1) - (__builtin_popcountll(msk));
      if(i == 0)
         rem = n-1;
      rem = 1LL << rem;
      if(__builtin_popcount(i) % 2 == 0)
         ans += rem;
      else
         ans -= rem;
   }
   
   cout<<ans;

   return 0;
}

Measured memory_bytes: 512