#pragma target("avx")
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef unordered_map<ll, ll> U_MAP;
typedef priority_queue<ll> pq;
typedef priority_queue<ll, vector<ll>, greater<ll>> rpq;
const int INF = 1e9, MOD = 1e9 + 7, ohara = 1e6 + 10;
const ll LINF = 1e18;

#define rep(i, n) for (ll(i) = 0; (i) < (int)(n); (i)++)
#define rrep(i, a, b) for (ll i = (a); i < (b); i++)
#define rrrep(i, a, b) for (ll i = (a); i >= (b); i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout << (x) << endl
#define doublecout(a) cout << fixed << setprecision(15) << a << endl;
#define fi first
#define se second
#define m_p make_pair
#define p_b push_back
string to_string(string s) { return '"' + s + '"'; }
string to_string(const char* s) { return to_string((string)s); }
string to_string(bool b) { return (b ? "true" : "false"); }
template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto& x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)

//------ Believe yourself as a genius!!!!!! ------

int dy[] = {1, 0, -1, 0};
int dx[] = {0, 1, 0, -1};
// int dy[]={-1,0,1,-1,1,-1,0,1};int dx[]={-1,-1,-1,0,0,1,1,1};
struct edge {
  ll to, cost;
};
string alph("abcdefghijklmnopqrstuvwxyz"), s;
ll n, cnt, ans, a[ohara], b[ohara], c, d[ohara], tmp, m, h, w, x, y, sum, k, q;
ll u[ohara], v[ohara];
vector<edge> g[ohara];
ll rui[ohara], pre[ohara], dp[60][1000000 + 100000];
int dat[100][100];

void dijkstra(ll s) {
  priority_queue<pair<ll, ll>, vector<pair<ll, ll>>, greater<pair<ll, ll>>> que;
  fill(d, d + n, LINF);
  fill(pre, pre + n, -1);
  d[s] = 0;
  que.push(pair<ll, ll>(0LL, s));
  while (!que.empty()) {
    pair<ll, ll> p = que.top();
    que.pop();
    ll v = p.second;
    if (d[v] < p.first) continue;
    rep(i, Size(g[v])) {
      edge e = g[v][i];
      if (d[e.to] > d[v] + e.cost) {
        d[e.to] = d[v] + e.cost;
        pre[e.to] = v;
        que.push(pair<ll, ll>(d[e.to], e.to));
      }
    }
  }
}

vector<ll> get_path(ll t) {
  vector<ll> path;
  for (; t != -1; t = pre[t]) {
    path.push_back(t);
  }
  reverse(all(path));
  return path;
}

int main(void) {
  cin.tie(0);
  cout.tie(0);
  ios::sync_with_stdio(false);

  cin >> n;
  rui[0] = 1;
  rrep(i, 1, n + 10) { rui[i] = rui[i - 1] * 2; }
  rep(i, n - 1) {
    cin >> a[i] >> b[i];
    a[i]--;
    b[i]--;
    g[a[i]].p_b({b[i], 1LL});
    g[b[i]].p_b({a[i], 1LL});
  }
  cin >> m;
  rep(i, m) {
    cin >> u[i] >> v[i];
    u[i]--;
    v[i]--;
    dijkstra(u[i]);
    vector<ll> pa = get_path(v[i]);
    rep(j, Size(pa)) { dat[i][pa[j]] = 1; }
  }
  dp[0][0] = 1;
  ll lim = (1LL << m);
  rrep(i, 1, n) {
    rep(j, lim) {
      //黒く塗る
      ll bit = j;
      rep(k, m) {
        if (dat[k][a[i - 1]] && dat[k][b[i - 1]]) {
          bit |= (1LL << k);
        }
      }
      dp[i][bit] += dp[i - 1][j];
      //白く塗る
      dp[i][j] += dp[i - 1][j];
    }
  }
  Cout(dp[n - 1][lim - 1]);
  return 0;
}


Measured memory_bytes: 459008