#include <bits/stdc++.h>
// created [2020/01/19] 20:36:43
#pragma GCC diagnostic ignored "-Wsign-compare"
#pragma GCC diagnostic ignored "-Wsign-conversion"

using i32   = int32_t;
using i64   = int64_t;
using u32   = uint32_t;
using u64   = uint64_t;
using uint  = unsigned int;
using usize = std::size_t;
using ll    = long long;
using ull   = unsigned long long;
using ld    = long double;
template<typename T, usize n>
using arr = T (&)[n];
template<typename T, usize n>
using c_arr = const T (&)[n];
template<typename T> constexpr T popcount(const T u) { return u ? static_cast<T>(__builtin_popcountll(static_cast<u64>(u))) : static_cast<T>(0); }
template<typename T> constexpr T log2p1(const T u) { return u ? static_cast<T>(64 - __builtin_clzll(static_cast<u64>(u))) : static_cast<T>(0); }
template<typename T> constexpr T msbp1(const T u) { return log2p1(u); }
template<typename T> constexpr T lsbp1(const T u) { return __builtin_ffsll(u); }
template<typename T> constexpr T clog(const T u) { return u ? log2p1(u - 1) : static_cast<T>(u); }
template<typename T> constexpr bool ispow2(const T u) { return u and (static_cast<u64>(u) & static_cast<u64>(u - 1)) == 0; }
template<typename T> constexpr T ceil2(const T u) { return static_cast<T>(1) << clog(u); }
template<typename T> constexpr T floor2(const T u) { return u == 0 ? static_cast<T>(0) : static_cast<T>(1) << (log2p1(u) - 1); }
template<typename T> constexpr bool btest(const T mask, const usize ind) { return static_cast<bool>((static_cast<u64>(mask) >> ind) & static_cast<u64>(1)); }
template<typename T> void bset(T& mask, const usize ind) { mask |= (static_cast<T>(1) << ind); }
template<typename T> void breset(T& mask, const usize ind) { mask &= ~(static_cast<T>(1) << ind); }
template<typename T> void bflip(T& mask, const usize ind) { mask ^= (static_cast<T>(1) << ind); }
template<typename T> void bset(T& mask, const usize ind, const bool b) { (b ? bset(mask, ind) : breset(mask, ind)); }
template<typename T> constexpr T bcut(const T mask, const usize ind) { return ind == 0 ? static_cast<T>(0) : static_cast<T>((static_cast<u64>(mask) << (64 - ind)) >> (64 - ind)); }
template<typename T> bool chmin(T& a, const T& b) { return (a > b ? a = b, true : false); }
template<typename T> bool chmax(T& a, const T& b) { return (a < b ? a = b, true : false); }
constexpr unsigned int mod                  = 1000000007;
template<typename T> constexpr T inf_v      = std::numeric_limits<T>::max() / 4;
template<typename Real> constexpr Real pi_v = Real{3.141592653589793238462643383279502884};
auto mfp = [](auto&& f) { return [=](auto&&... args) { return f(f, std::forward<decltype(args)>(args)...); }; };

template<typename T>
T in()
{
    T v;
    return std::cin >> v, v;
}
template<typename T, typename Uint, usize n, usize i>
T in_v(typename std::enable_if<(i == n), c_arr<Uint, n>>::type) { return in<T>(); }
template<typename T, typename Uint, usize n, usize i>
auto in_v(typename std::enable_if<(i < n), c_arr<Uint, n>>::type& szs)
{
    const usize s = (usize)szs[i];
    std::vector<decltype(in_v<T, Uint, n, i + 1>(szs))> ans(s);
    for (usize j = 0; j < s; j++) { ans[j] = in_v<T, Uint, n, i + 1>(szs); }
    return ans;
}
template<typename T, typename Uint, usize n>
auto in_v(c_arr<Uint, n> szs) { return in_v<T, Uint, n, 0>(szs); }
template<typename... Types>
auto in_t() { return std::tuple<std::decay_t<Types>...>{in<Types>()...}; }
struct io_init
{
    io_init()
    {
        std::cin.tie(nullptr), std::ios::sync_with_stdio(false);
        std::cout << std::fixed << std::setprecision(20);
    }
    void clear()
    {
        std::cin.tie(), std::ios::sync_with_stdio(true);
    }
} io_setting;

int out() { return 0; }
template<typename T>
int out(const T& v) { return std::cout << v, 0; }
template<typename T>
int out(const std::vector<T>& v)
{
    for (usize i = 0; i < v.size(); i++) {
        if (i > 0) { std::cout << ' '; }
        out(v[i]);
    }
    return std::cout << "\n", 0;
}
template<typename T1, typename T2>
int out(const std::pair<T1, T2>& v) { return out(v.first), std::cout << ' ', out(v.second), 0; }
template<typename T, typename... Args>
int out(const T& v, const Args... args) { return out(v), std::cout << ' ', out(args...), 0; }
template<typename... Args>
int outln(const Args... args) { return out(args...), std::cout << '\n', 0; }
template<typename... Args>
void outel(const Args... args) { return out(args...), std::cout << std::endl, 0; }
#    define SHOW(...) static_cast<void>(0)
constexpr ull TEN(const usize n) { return n == 0 ? 1ULL : TEN(n - 1) * 10ULL; }

template<typename T, typename Uint, usize n, usize i>
auto make_v(typename std::enable_if<(i == n), c_arr<Uint, n>>::type, const T& v = T{}) { return v; }
template<typename T, typename Uint, usize n, usize i>
auto make_v(typename std::enable_if<(i < n), c_arr<Uint, n>>::type szs, const T& v = T{})
{
    const usize s = (usize)szs[i];
    return std::vector<decltype(make_v<T, Uint, n, i + 1>(szs, v))>(s, make_v<T, Uint, n, i + 1>(szs, v));
}
template<typename T, typename Uint, usize n>
auto make_v(c_arr<Uint, n> szs, const T& t = T{}) { return make_v<T, Uint, n, 0>(szs, t); }


template<typename SemiGroup>
class sparse_table
{
public:
    using semigroup_type = SemiGroup;
    using value_type     = typename semigroup_type::value_type;
    template<typename InIt>
    sparse_table(const InIt first, const InIt last) : lg{clog(static_cast<usize>(std::distance(first, last) + 1))}, table(lg, std::vector<value_type>(1 << lg))
    {
        const usize cap = 1 << lg;
        for (usize d = 0, base = 1; d < lg; d++, base <<= 1) {
            std::copy(first, last, table[d].begin());
            for (usize b = 0; b < cap / base; b++) {
                if (b % 2 == 1) {
                    for (usize i = 1; i < base; i++) { table[d][b * base + i] = semigroup_type::merge(table[d][b * base + i - 1], table[d][b * base + i]); }
                } else {
                    for (usize i = 1; i < base; i++) { table[d][(b + 1) * base - i - 1] = semigroup_type::merge(table[d][(b + 1) * base - i - 1], table[d][(b + 1) * base - i]); }
                }
            }
        }
    }
    value_type fold(const usize l, const usize r) const
    {
        assert(l < r);
        if (r - l == 1) { return table[0][l]; }
        const usize d = log2p1(r ^ l) - 1;
        return semigroup_type::merge(table[d][l], table[d][r - 1]);
    }

private:
    const usize lg;
    std::vector<std::vector<value_type>> table;
};
template<typename Value, typename Comp = std::less<Value>, typename Bucket = uint64_t>
class static_rmq
{
public:
    using value_type      = Value;
    using comparator_type = Comp;
    template<typename InIt>
    static_rmq(const InIt first, const InIt last)
        : sz{static_cast<usize>(std::distance(first, last))}, bn{wind(sz + bs - 1)}, val{first, last}, bucket_val([&]() {
              std::vector<value_type> ans(bn);
              for (usize i = 0; i < sz; i++) { ans[wind(i)] = i % bs == 0 ? val[i] : std::min(ans[wind(i)], val[i], comparator_type{}); }
              return ans;
          }()),
          masks(sz, 0),
          st(bucket_val.begin(), bucket_val.end())
    {
        for (usize i = 0; i < bn; i++) {
            std::vector<usize> g(bs, sz);
            std::stack<usize> stack;
            for (usize j = 0; j < bs and ind(i, j) < sz; j++) {
                for (; not stack.empty() and not comparator_type{}(val[stack.top()], val[ind(i, j)]); stack.pop()) {}
                g[j] = stack.empty() ? sz : stack.top(), stack.push(ind(i, j));
            }
            for (usize j = 0; j < bs and ind(i, j) < sz; j++) { masks[ind(i, j)] = g[j] == sz ? static_cast<bucket_type>(0) : (masks[g[j]] | static_cast<bucket_type>(1) << (g[j] - i * bs)); }
        }
    }
    value_type fold(const usize l, const usize r) const
    {
        assert(l < r), assert(r <= sz);
        const usize lb = (l + bs - 1) / bs, rb = r / bs;
        if (lb > rb) {
            return brmq(l, r);
        } else {
            return lb < rb
                       ? (l < bs * lb
                              ? (bs * rb < r
                                     ? std::min({st.fold(lb, rb), brmq(l, bs * lb), brmq(bs * rb, r)}, comparator_type{})
                                     : std::min(st.fold(lb, rb), brmq(l, bs * lb), comparator_type{}))
                              : (bs * rb < r
                                     ? std::min(st.fold(lb, rb), brmq(bs * rb, r), comparator_type{})
                                     : st.fold(lb, rb)))
                       : (l < bs * lb
                              ? (bs * rb < r
                                     ? std::min(brmq(l, bs * lb), brmq(bs * rb, r), comparator_type{})
                                     : brmq(l, bs * lb))
                              : (bs * rb < r
                                     ? brmq(bs * rb, r)
                                     : value_type{}));
        }
    }

private:
    using bucket_type            = Bucket;
    static constexpr usize bs    = sizeof(bucket_type) * 8;
    static constexpr usize bslog = log2p1(bs) - 1;
    static constexpr usize wind(const usize n) { return n >> (bslog); }
    static constexpr usize bind(const usize n) { return bcut(n, bslog); }
    static constexpr usize ind(const usize w, const usize b) { return (w << bslog) | b; }
    value_type brmq(const usize l, usize r) const
    {
        r--;
        const Bucket w = masks[r] >> (l % bs);
        return w == 0 ? val[r] : val[l + lsbp1(w) - 1];
    }
    struct min
    {
        using value_type = Value;
        static value_type merge(const value_type& a, const value_type& b) { return std::min(a, b, comparator_type{}); }
    };

    const usize sz, bn;
    std::vector<value_type> val, bucket_val;
    std::vector<Bucket> masks;
    sparse_table<min> st;
};

template<typename Cost = usize>
struct edge
{
    using cost_type = Cost;
    usize u, v;
    Cost c;
    edge(const usize u, const usize v) : u{u}, v{v}, c{1} {}
    edge(const usize u, const usize v, const Cost& c) : u{u}, v{v}, c{c} {}
    operator usize() const { return v; }
    usize from() const { return u; }
    usize to() const { return v; }
    Cost cost() const { return c; }
    friend std::ostream& operator<<(std::ostream& os, const edge& e) { return os << e.u << "->" << e.v << ":" << e.c; }
};
template<typename Edge>
class base_graph
{
public:
    base_graph(const usize n) : v{n}, es(n), res(n) {}
    void add_edge(const usize u, const usize v, const bool bi = false)
    {
        es[u].emplace_back(u, v), res[v].emplace_back(v, u);
        if (bi) { es[v].emplace_back(v, u), res[u].emplace_back(u, v); }
    }
    template<typename Cost>
    void add_edge(const usize u, const usize v, const Cost& c, const bool bi = false)
    {
        es[u].emplace_back(u, v, c), res[v].emplace_back(v, u, c);
        if (bi) { es[v].emplace_back(v, u, c), res[u].emplace_back(u, v, c); }
    }
    std::vector<Edge>& operator[](const usize u) { return es[u]; }
    const std::vector<Edge>& operator[](const usize u) const { return es[u]; }
    std::vector<Edge>& from(const usize u) { return es[u]; }
    const std::vector<Edge>& from(const usize u) const { return es[u]; }
    std::vector<Edge>& to(const usize v) { return res[v]; }
    const std::vector<Edge>& to(const usize v) const { return res[v]; }
    usize size() const { return v; }

private:
    usize v;
    std::vector<std::vector<Edge>> es, res;
};
template<typename Edge>
using base_tree = base_graph<Edge>;
using graph     = base_graph<edge<>>;
using tree      = base_graph<edge<>>;
template<typename Cost>
using cost_graph = base_graph<edge<Cost>>;
template<typename Cost>
using cost_tree = base_graph<edge<Cost>>;
template<typename Edge = edge<>>
class lca_manager
{
public:
    lca_manager(const base_tree<Edge>& tree, const std::size_t root = 0) : left(tree.size(), 0),
                                                                           depth([&]() {
                                                                               std::vector<std::pair<std::size_t, std::size_t>> ans;
                                                                               std::vector<bool> used(tree.size(), false);
                                                                               auto dfs = [&](auto&& self, const std::pair<std::size_t, std::size_t>& s) -> void {
                                                                                   const std::size_t pos = s.second;
                                                                                   used[pos] = true, left[pos] = ans.size(), ans.push_back(s);
                                                                                   for (const auto& e : tree[pos]) {
                                                                                       const std::size_t to = e.to();
                                                                                       if (used[to]) { continue; }
                                                                                       self(self, {s.first + 1, to}), ans.push_back(s);
                                                                                   }
                                                                               };
                                                                               dfs(dfs, {0, root});
                                                                               return ans;
                                                                           }()),
                                                                           stable(depth.begin(), depth.end()) {}
    std::size_t operator()(const std::size_t u, const std::size_t v) const
    {
        const std::size_t ul = left[u], vl = left[v];
        return stable.fold(std::min(ul, vl), std::max(ul, vl) + 1).second;
    }

private:
    std::vector<std::size_t> left;
    std::vector<std::pair<std::size_t, std::size_t>> depth;
    static_rmq<std::pair<std::size_t, std::size_t>> stable;
};
int main()
{
    auto N = in<int>();
    graph g(N);
    for (int i = 0; i < N - 1; i++) {
        const auto u = in<int>() - 1, v = in<int>() - 1;
        g.add_edge(u, v, true);
    }
    lca_manager<> lca(g);
    auto M = in<int>();
    std::vector<int> u(M), v(M), l(M);
    for (int i = 0; i < M; i++) {
        u[i] = in<int>() - 1, v[i] = in<int>() - 1;
        l[i] = lca(u[i], v[i]);
    }
    std::vector<int> par(N);
    mfp([&](auto&& self, const int s, const int p) -> void {
        for (const int to : g[s]) {
            if (to == p) { continue; }
            par[to] = s;
            self(self, to, s);
        }
    })(0, -1);
    int P = 1 << M;
    std::vector<ll> dp(P, 0);
    for (int m = 0; m < P; m++) {
        std::vector<bool> used(N, false);
        used[0] = true;
        for (int j = 0; j < M; j++) {
            if (not btest(m, j)) { continue; }
            const int lv = l[j];
            for (int a = u[j]; a != lv; a = par[a]) { used[a] = true; }
            for (int a = v[j]; a != lv; a = par[a]) { used[a] = true; }
        }
        int res = 0;
        for (int i = 0; i < N; i++) {
            if (not used[i]) { res++; }
        }
        dp[m] = 1LL << res;
    }
    ll ans = 0;
    for (int m = 0; m < P; m++) { ans += dp[m] * (popcount(m) % 2 == 0 ? 1LL : -1LL); }
    outln(ans);
    return 0;
}


Measured memory_bytes: 8448