#include <bits/stdc++.h>


using namespace std;
#define rep(i,n) for (int i = 0; i < (int)(n); ++i)
#define reps(i,n) for (int i = 1; i <= (int)(n); ++i)
#define repd(i,n) for (int i = (int)(n - 1); i >= 0; --i)
#define repds(i,n) for (int i = (int)(n); i > 0; --i)
#define loop(i,x,n) for (int i = (int)(x); i < (n); ++i)
#define loops(i,x,n) for (int i = (int)(x); i <= (n); ++i)
#define loopd(i,x,n) for (int i = (int)(x); i > (n); --i)
#define loopds(i,x,n) for (int i = (int)(x); i >= (n); --i)
#define itrep(i,s) for (auto i = begin(s); i != end(s); ++i)
#define itrepd(i,s) for (auto i = --end(s); i != begin(s); --i)
#define all(f,x,...) [&](decltype(x)& whole) { return (f)(begin(whole), end(whole), ##__VA_ARGS__); }(x)
#define rall(f,x,...) [&](decltype(x)& whole) { return (f)(rbegin(whole), rend(whole), ##__VA_ARGS__); }(x)
using ll = long long;
using ld = long double;
constexpr ll inf = static_cast<ll>(1e17);
constexpr int iinf = static_cast<int>(1e9);
constexpr double dinf = 1e10;
constexpr ld ldinf = 1e17;
ll mod = static_cast<ll>(1e9 + 7);
std::ostream& endn(std::ostream& os) { return os.put(os.widen('\n')); }
template<class T> constexpr int sz(const T& a) { return (int)a.size(); }
template<class T> constexpr T pow2(const T a) { return a * a; }
template<class T, class ... Args> constexpr T mins(T& a, Args... args) { return a = min<T>({ a, args... }); }
template<class T, class... Args> constexpr T maxs(T& a, Args... args) { return a = max<T>({ a,args... }); }
template<typename A, size_t N, typename T>
void fillArray(A(&array)[N], const T& val) { std::fill((T*)array, (T*)(array + N), val); }

template<class T>
class LCA {
public:
    LCA() :root(0), V(0), logV(0), to(0), parent(0), depth(0) {}
    LCA(int v, int r = 0) :root(r), V(v), logV((int)std::ceil(std::log2(v)) + 1),
        to(v, std::vector<Edge>(0)), parent(logV, std::vector<int>(v, 0)), depth(v, 0), dist(v, 0) {}
    void resize(int v, int r = 0) { *this = { v,r }; }
    void addEdge(int a, int b, T c = 1) { to[a].emplace_back(b, c); to[b].emplace_back(a, c); }
    void init() {
        dfs(root, -1, 0);
        for (int k = 0; k + 1 < logV; ++k)
            for (int i = 0; i < V; ++i)
                if (parent[k][i] < 0) parent[k + 1][i] = -1;
                else parent[k + 1][i] = parent[k][parent[k][i]];
    }
    int operator()(int u, int v) {
        if (depth[u] > depth[v]) std::swap(u, v);
        for (int k = 0; k < logV; ++k)
            if ((depth[v] - depth[u]) >> k & 1) v = parent[k][v];
        if (u == v) return u;
        for (int k = logV - 1; k >= 0; --k)
            if (parent[k][u] != parent[k][v]) {
                u = parent[k][u]; v = parent[k][v];
            }
        return parent[0][u];
    }
    T length(int u, int v) {
        int c = (*this)(u, v);
        return dist[u] + dist[v] - dist[c] * 2;
    }
    int par(int i, int cnt = 0) { return parent[cnt][i]; }
private:
    void dfs(int v, int p = -1, int d = 0, T c = 0) {
        parent[0][v] = p;
        depth[v] = d;
        dist[v] = c;
        int n = (int)to[v].size();
        for (int i = 0; i < n; ++i) {
            auto ne = to[v][i];
            if (ne.to != p) dfs(ne.to, v, d + 1, c + ne.cost);
        }
    }
    struct Edge {
        int to;
        T cost;
        Edge(int t = 0, T c = 1) :to(t), cost(c) {}
    };
    int root, V, logV;
    std::vector<std::vector<Edge>> to;
    std::vector<std::vector<int>> parent;
    std::vector<int> depth;
    std::vector<T> dist;
};

int n, m;
int a[55], b[55];
int u[25], v[25];
void solve() {
    cin >> n;
    rep(i, n - 1) { cin >> a[i] >> b[i]; --a[i]; --b[i]; }
    cin >> m;
    rep(i, m) { cin >> u[i] >> v[i]; --u[i]; --v[i]; }

    LCA<int> lca(n);
    map<pair<int, int>, int> mp;
    rep(i, n - 1) {
        lca.addEdge(a[i], b[i]);
        mp[{a[i], b[i]}] = mp[{b[i], a[i]}] = i;
    }

    lca.init();

    ll ans = 0;
    reps(s, (1 << m) - 1) {
        vector<bool> use(n - 1, false);
        int cnt = 0;
        rep(i, m) {
            if (((s >> i) & 1) == 1) {
                ++cnt;
                auto root = lca(u[i], v[i]);
                int now = u[i];
                while (now != root) {
                    auto ne = lca.par(now);
                    use[mp[{now, ne}]] = true;
                    now = ne;
                }
                now = v[i];
                while (now != root) {
                    auto ne = lca.par(now);
                    use[mp[{now, ne}]] = true;
                    now = ne;
                }
            }
        }

        ll res = 1;
        rep(i, n - 1) if (!use[i]) res *= 2;
        if (cnt % 2 == 0) ans -= res;
        else ans += res;
    }

    cout << (ll)pow(2, n - 1) - ans << endn;

}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    solve();
    cout << flush;
    return 0;
}


Measured memory_bytes: 384