#include <algorithm>
#include <cassert>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <list>
#include <numeric>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

using namespace std;

#define int long long int
#define rep(i, n) for (int i = 0; i < n; ++i)
#define all(x) (x).begin(), (x).end()
#define capi(x) int x;cin>>x
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

using vi = vector<int>;

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;}

using Edge = int;
using Graph = vector<vector<Edge>>;

class LCS {
public:
    vector<vector<int>> parent;
    vector<int> depth;
    const int size;

    LCS(const Graph& graph, Edge root) :
        parent(vector(log2(graph.size()) + 1, vector(graph.size(), 0ll))),
        depth(vector(graph.size(), 0ll)),
        size(graph.size()) {
        dfs(graph, root, -1, 0);
        for (int k = 0; k < (int)(log2(size)); ++k) {
            for (int v = 0; v < size; ++v) {
                if (parent[k][v] < 0) {
                    parent[k + 1][v] = -1;
                } else {
                    parent[k + 1][v] = parent[k][parent[k][v]];
                }
            }
        }
    }

    int get(int u, int v) {
        if (depth[u] > depth[v]) swap(u, v);

        for (int k = 0; k < log2(size) + 1; ++k) {
            if ((depth[v] - depth[u]) >> k & 1) {
                v = parent[k][v];
            }
        }
        if (u == v) return u;
        for (int k = log2(size); k >= 0; --k) {
            if (parent[k][u] != parent[k][v]) {
                u = parent[k][u];
                v = parent[k][v];
            }
        }

        return parent[0][u];
    }

    int calc_distance(int u, int v) {
        return depth[u] + depth[v] - depth[get(u, v)] * 2;
    }

    bool contains(int u, int v, int a) {
        return calc_distance(u, a) + calc_distance(v, a) == calc_distance(u, v);
    }
private:
    void dfs(const Graph& graph, int v, int p, int d) {
        parent[0][v] = p;
        depth[v] = d;

        for (auto &e: graph[v]) {
            if (e != p) dfs(graph, e, v, d + 1);
        }
    }
};

signed main() {
    Graph g;
    capi(n);
    g.assign(n + 1, vector<int>());
    vector<pair<int, int>> vp;

    rep(i, n - 1) {
        int a, b;
        cin >> a >> b;

        g[a].push_back(b);
        g[b].push_back(a);
        vp.push_back(make_pair(a, b));
    }

    LCS lcs(g, 1);

    vector<bitset<50>> vc;

    capi(m);
    rep(i, m) {
        int u, v;
        cin >> u >> v;

        bitset<50> bs;
        rep(j, n - 1) {
            if (lcs.contains(u, v, vp[j].first) && lcs.contains(u, v, vp[j].second)) {
                bs.set(j);
            }
        }

        vc.push_back(bs);
    }

    int ans = 0;
   
    rep(i, 1ll << m) {
        int bc = 0;

        if (i == 0) {
            ans += 1ll << (n - 1);
            continue;
        }

        bitset<50> bs;

        rep(j, m) {
            if (i & (1ll << j)) {
                ++bc;
                bs |= vc[j];
            }
        }

        if (bc % 2) ans -= 1ll << (n - 1 - bs.count());
        else ans += 1ll << (n - 1 - bs.count());
    }

    cout << ans;

    return 0;
}

Measured memory_bytes: 3312