#include "bits/stdc++.h"
using namespace std;
using ll     = long long;
using pii    = pair<int, int>;
using pll    = pair<ll, ll>;
using vi     = vector<int>;
using vl     = vector<ll>;
using vvi    = vector<vi>;
using vvl    = vector<vl>;
const ll INF = 1LL << 60;
const ll MOD = 1000000007;
template <class T>
bool chmax(T &a, const T &b) {
    return (a < b) ? (a = b, 1) : 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    return (b < a) ? (a = b, 1) : 0;
}
template <class C>
void print(const C &c, std::ostream &os = std::cout) {
    std::copy(std::begin(c), std::end(c), std::ostream_iterator<typename C::value_type>(os, " "));
    os << std::endl;
}

template <typename T>
struct Dijkstra {
    using P = pair<T, int>;
    int n;
    T inf;
    vector<T> dist;
    vector<int> rev;
    vector<vector<pair<int, T>>> G;

    Dijkstra(vector<vector<pair<int, T>>> &G_) : G(G_) {
        n   = G.size();
        inf = numeric_limits<T>::max();
    }

    void build(int s) {
        dist.clear();
        dist.resize(n, inf);
        rev.clear();
        rev.resize(n, -1);
        priority_queue<P, vector<P>, greater<P>> q;
        dist[s] = 0;
        q.emplace(dist[s], s);
        while (!q.empty()) {
            P p = q.top();
            q.pop();
            int v = p.second;
            if (dist[v] < p.first)
                continue;
            for (auto &e : G[v]) {
                int u = e.first;
                T c   = e.second;
                if (dist[u] > dist[v] + c) {
                    dist[u] = dist[v] + c;
                    rev[u]  = v;
                    q.emplace(dist[u], u);
                }
            }
        }
    }
    vector<int> get_path(int t) {
        vector<int> path;
        for (; t != -1; t = rev[t])
            path.push_back(t);
        reverse(path.begin(), path.end());
        return path;
    }
};

int main() {
    int n;
    cin >> n;
    vector<vector<pii>> edges(n);
    map<pii, int> idx;
    for (int i = 0; i < n - 1; ++i) {
        int a, b;
        cin >> a >> b;
        a--, b--;
        if (a > b)
            swap(a, b);
        edges[a].emplace_back(b, 1);
        edges[b].emplace_back(a, 1);
        idx[{a, b}] = i;
    }
    int m;
    cin >> m;
    vi u(m), v(m);
    for (int i = 0; i < m; ++i) {
        cin >> u[i] >> v[i];
        u[i]--, v[i]--;
    }
    Dijkstra<int> t(edges);
    vector<bitset<20>> usededges(m, 0);

    for (int i = 0; i < m; ++i) {
        t.build(u[i]);
        vi path = t.get_path(v[i]);
        for (int j = 1; j < (int)path.size(); ++j) {
            int l = path[j - 1];
            int r = path[j];
            if (l > r)
                swap(l, r);
            usededges[i][idx[{l, r}]] = 1;
        }
    }
    vvl dp(n, vl(1 << m, 0));
    dp[0][0] = 1;
    for (int i = 1; i < n; ++i) {
        for (int j = 0; j < (1 << m); ++j) {
            dp[i][j] += dp[i - 1][j];
            int k = j;
            for (int l = 0; l < m; ++l) {
                if (usededges[l][i - 1])
                    k |= (1 << l);
            }
            dp[i][k] += dp[i - 1][j];
        }
    }
    cout << dp[n - 1][(1 << m) - 1] << "\n";
    // ll ret = 0;
    // for (int i = 0; i < (1 << m); ++i) {
    //     int bits        = __builtin_popcount(i);
    //     bitset<20> used = 0;
    //     for (int j = 0; j < m; ++j) {
    //         if (i & (1 << j)) {
    //             used |= usededges[j];
    //         }
    //     }
    //     int k = used.count();
    //     ret += (1LL << (n - 1 - k)) * (bits % 2 == 1 ? -1 : 1);
    // }
    // cout << ret << "\n";
    return 0;
}

Measured memory_bytes: 418304