#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <stack>
#include <functional>

#ifdef LOCAL
    #define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
    #define eprintf(...) 42
#endif

#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define repp(i, m, n) for(int i = m, i##_len = (n); i < i##_len; ++i)
#define reprev(i, n) for(int i = (n-1LL); i >= 0; --i)
#define all(x) (x).begin(), (x).end()
template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair <int,int> P;
typedef long double ld;

template< typename T >
struct edge {
  int src, to;
  T cost;

  edge(int to, T cost) : src(-1), to(to), cost(cost) {}

  edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}

  edge &operator=(const int &x) {
    to = x;
    return *this;
  }

  operator int() const { return to; }
};

template< typename T >
using Edges = vector< edge< T > >;
template< typename T >
using WeightedGraph = vector< Edges< T > >;
using UnWeightedGraph = vector< vector< int > >;
template< typename T >
using Matrix = vector< vector< T > >;

template< typename T >
void warshall_floyd(Matrix< T > &g, T INF) {
  for(int k = 0; k < g.size(); k++) {
    for(int i = 0; i < g.size(); i++) {
      for(int j = 0; j < g.size(); j++) {
        if(g[i][k] == INF || g[k][j] == INF) continue;
        g[i][j] = min(g[i][j], g[i][k] + g[k][j]);
      }
    }
  }
}

ll INF = 1LL << 60;
ll dp[2][(1 << 20)] = {1};
int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, m;
    cin >> n;
    Matrix< ll > mat(n, vector< ll >(n, INF));
    rep (i, n) mat[i][i] = 0;
    // rep (i, n - 1) {
    for (ll i = 0; i < n - 1; i++) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        mat[b][a] = mat[a][b] = (1LL << i);
    }
    warshall_floyd(mat, INF);
    vector<ll> x;
    cin >> m;
    rep (i, m) {
        int u, v;
        cin >> u >> v;
        u--; v--;
        x.push_back(mat[u][v]);
    }
    rep (i, x.size()) eprintf("%lld ", x[i]); eprintf("\n");
    // dp[used][digit]
    vector<int> dig(50); // どこの辺がOKになるか？
    rep (i, n) {
        int tmp = 0;
        rep (j, m) {
            if (x[j] & (1LL << i)) tmp += (1LL << j);
        }
        dig[i] = tmp;
    }
    // rep (i, n - 1) eprintf("%d", dig[i]); eprintf("\n");
    rep (i, n - 1) {
        rep (j, (1 << m)) dp[(i + 1) % 2][j] = 0;
        rep (j, (1 << m)) {
            // if (i == n - 2 && (j | dig[i]) == 7) eprintf("%lld", dp[i % 2][j]);
            // if (i == n - 2 && j == 7) eprintf("%lld", dp[i % 2][j]);
            dp[(i + 1) % 2][(j | dig[i])] += dp[i % 2][j];
            dp[(i + 1) % 2][j] += dp[i % 2][j];
        }
        // eprintf("\n");
        rep (j, (1 << m)) eprintf("%lld ", dp[i % 2][j]); eprintf("\n");
        rep (j, (1 << m)) eprintf("%lld ", dp[(i + 1) % 2][j]); eprintf("\n");
    }
    cout << dp[(n - 1) % 2][(1 << m) - 1] << "\n";
    return 0;
}

Measured memory_bytes: 16640