#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <bitset>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <string>
#include <chrono>
#include <random>
#include <cmath>
#include <cassert>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <functional>
#include <sstream>

using namespace std;

class Solution {
public:
    long long solve(int n, vector<pair<int,int>>& edges, vector<pair<int,int>>& paths) {
        int m = paths.size();
        int M = 1 << m;
        vector<vector<pair<int, int>>> graph(n);
        for (int i = 0; i < edges.size(); ++i) {
            int u = edges[i].first, v = edges[i].second;
            graph[u].emplace_back(v, i);
            graph[v].emplace_back(u, i);
        }

        int rt = 0;
        vector<int> ord;
        vector<int> pars(n, -1);
        ord.push_back(rt);

        for (int i = 0; i < ord.size(); ++i) {
            int u = ord[i];
            for (auto& e : graph[u]) {
                int v = e.first;
                if (v == pars[u]) {
                    continue;
                }
                pars[v] = u;
                ord.push_back(v);
            }
        }

        vector<int> masks(n, 0);

        function<bool(int,int,int,vector<int>&)> dfs = [&](int u, int t, int p, vector<int>& path) {
            if (u == t) {
                return true;
            }
            for (auto& e : graph[u]) {
                int v = e.first;
                int idx = e.second;
                if (v == p) {
                    continue;
                }
                path.push_back(idx);
                if (dfs(v, t, u, path)) {
                    return true;
                }
                path.pop_back();
            }
            return false;
        };

        for (int i = 0; i < m; ++i) {
            int u = paths[i].first, v = paths[i].second;
            vector<int> P;
            dfs(u, v, -1, P);
            for (auto x : P) {
                masks[x] |= 1 << i;
            }
        }

        auto inc = [&](vector<long long>& S, int n) {
            for (int i = 0; i < n; ++i) {
                for (int j = 0; j < (1 << n); ++j) {
                    if (j & (1 << i)) {
                        S[j] += S[j ^ (1 << i)];
                    }
                }
            }
        };
        auto exc = [&](vector<long long>& S, int n) {
            for (int i = 0; i < n; ++i) {
                for (int j = 0; j < (1 << n); ++j) {
                    if (j & (1 << i)) {
                        S[j] -= S[j ^ (1 << i)];
                    }
                }
            }
        };

        auto s2u = [&](vector<long long>& S, int n, int s, int v) {
            for (int i = s; i < (1 << n); i = (i + 1) | s) {
                S[i] += v;
            }
        };

        vector<vector<long long>> dp(n, vector<long long>(M, 0));
        reverse(ord.begin(), ord.end());

        for (auto u : ord) {
            s2u(dp[u], m, 0, 1);
            // dp[u][0] = 1;
            int p = pars[u];
            if (p != -1) {
                for (auto& e : graph[p]) {
                    if (e.first == u) {
                        s2u(dp[u], m, masks[e.second], 1);
                        // dp[u][masks[e.second]] += 1;
                        break;
                    }
                }
            }
            // inc(dp[u], m);
            for (auto& e : graph[u]) {
                int v = e.first;
                int idx = e.second;
                if (v == pars[u]) {
                    continue;
                }
                for (int i = 0; i < M; ++i) {
                    dp[u][i] *= dp[v][i];
                }
            }
        }

        exc(dp[rt], m);
        return dp[rt][M - 1];
    }
};

int main(int argc, char** argv) {
    ios::sync_with_stdio(false);
    cin.tie(0);

    int n;
    cin >> n;
    vector<pair<int,int>> edges;
    for (int i = 0; i + 1 < n; ++i) {
        int u, v;
        cin >> u >> v;
        --u, --v;
        edges.emplace_back(u, v);
    }
    int m;
    cin >> m;
    vector<pair<int,int>> paths;
    for (int i = 0; i < m; ++i) {
        int u, v;
        cin >> u >> v;
        --u, --v;
        paths.emplace_back(u, v);
    }

    Solution sol;
    cout << sol.solve(n, edges, paths) << "\n";

    return 0;
}

Measured memory_bytes: 418304