#include <iostream>
#include <fstream>
#include <algorithm>
#include <chrono>
#include <random>
#include <vector>
#include <string>
#include <cmath>
#include <bitset>
#include <list>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cassert>

#define sq(x) ((x) * (x))
#define err(x) cerr << "["#x"]  " << (x) << "\n";
#define errp(x) cerr << "["#x"]  {" << ((x).first) << ", " << ((x).second) << "}\n";
#define errv(x) {cerr << "["#x"]  [";for(const auto& ___ : (x)) cerr << ___ << ", "; cerr << "]\n";}
#define errvn(x, n) {cerr << "["#x"]  [";for(auto ___ = 0; ___ < (n); ++___) cerr << (x)[___] << ", "; cerr << "]\n";}
#define errf() cerr << "\n\n";

//#pragma GCC optimize("Ofast, unroll-loops", "omit-frame-pointer","inline")
//#pragma GCC option("arch=native","tune=native","no-zero-upper")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native,avx2")

using namespace std;

using ll = long long;
using ull = unsigned long long;
using ld = long double;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int getrnd(int l, int r) {
    return uniform_int_distribution<int>(l, r)(rng);
}

template <typename T1, typename T2>
bool relax(T1& a, const T2& b) {
    if (a > b) {
        a = b;
        return 1;
    }
    return 0;
}

template <typename T1, typename T2>
bool strain(T1& a, const T2& b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}

// :::::::::::::::::::::::::::::::

const int N = 53;

int n, m, dst[N], from[N][N], fi[N][N];
bitset<N> all_paths[N][N];
vector<int> graph[N], ind[N];

void bfs(int v) {
    for (int i = 0; i < n; ++i)
        dst[i] = N + 1, from[v][i] = fi[v][i] = -1;
    
    queue<int> scope;
    scope.emplace(v);
    dst[v] = 0;
    
    while (!scope.empty()) {
        int cur = scope.front();
        scope.pop();
        
        int temp = 0;
        for (int to : graph[cur]) {
            if (dst[to] > dst[cur] + 1) {
                dst[to] = dst[cur] + 1;
                from[v][to] = cur;
                fi[v][to] = ind[cur][temp];
                
                scope.emplace(to);
            }
            ++temp;
        }
    }
}

void get_path(int a, int b, bitset<N>& res) {
    while (b != a) {
        res.set(fi[a][b]);
        b = from[a][b];
    }
}

void solve() {
    cin >> n;
    
    for (int i = 0; i < n - 1; ++i) {
        int a, b;
        cin >> a >> b;
        --a; --b;
        
        graph[a].emplace_back(b);
        ind[a].emplace_back(i);
        graph[b].emplace_back(a);
        ind[b].emplace_back(i);
    }
    cin >> m;
    
    vector<pair<int, int>> bad;
    for (int i = 0; i < m; ++i) {
        int a, b;
        cin >> a >> b;
        
        bad.emplace_back(a - 1, b - 1);
    }
    
    for (int i = 0; i < n; ++i) {
        bfs(i);
        for (int j = 0; j < n; ++j)
            get_path(i, j, all_paths[i][j]);
    }
    
    ll ans = 1LL << (n - 1);
    for (int msk = 1; msk < (1 << m); ++msk) {
        int sign = 0;
        for (int i = 0; i < m; ++i)
            if ((msk >> i) & 1) ++sign;
        if (sign % 2) sign = -1;
        else sign = 1;
        
        bitset<N> path;
        for (int i = 0; i < m; ++i) {
            if ((msk >> i) & 1) {
                int a = bad[i].first, b = bad[i].second;
                
                path |= all_paths[a][b];
            }
        }
        int sz = (int) path.count();
        ans += sign * (1LL << (n - 1 - sz));
    }
    cout << ans << '\n';
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(nullptr); cout.tie(nullptr);
    srand(time(0));
    
    int t = 1;
//    cin >> t;
    while (t--)
        solve();
    
    return 0;
}


Measured memory_bytes: 384