#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i, n) for (int i = 0; i < n; i++)
#define ALL(a) (a).begin(), (a).end()
typedef vector<int> vi;
const int INF = 1LL << 58;
// const int INF = 1 << 29;
const int MOD = 1000000007;
const int MAX_N = 200100;

vi d[50][50];
bool dp[(1 << 20)][50];

int fn(int a)
{
    int ans = 1;
    while (a > 0)
    {
        a--;
        ans *= 2;
    }
    return ans;
}

signed main()
{
    //  以降 cin の入力元が 'input.txt' になる
    // std::ifstream in("F/in/dense_01.txt");
    // std::cin.rdbuf(in.rdbuf());
    int N, M;
    cin >> N;
    REP(i, N - 1)
    {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        d[a][b].emplace_back(i);
        d[b][a].emplace_back(i);
    }
    REP(k, N)
    {
        REP(i, N)
        {
            REP(j, N)
            {
                int a = d[i][k].size();
                int b = d[k][j].size();
                int c = d[i][j].size();
                if (a > 0 && b > 0)
                {
                    if (c > 0)
                    {
                        if (a + b < c)
                        {
                            d[i][j].clear();
                            REP(s, a)
                            d[i][j].push_back(d[i][k][s]);
                            REP(s, b)
                            d[i][j].push_back(d[k][j][s]);
                        }
                    }
                    else
                    {
                        REP(s, a)
                        d[i][j].push_back(d[i][k][s]);
                        REP(s, b)
                        d[i][j].push_back(d[k][j][s]);
                    }
                }
            }
        }
    }

    cin >> M;
    vector<pair<int, int>> query;
    REP(i, M)
    {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        query.emplace_back(a, b);
    }

    REP(bit, (1 << M))
    {
        REP(j, N - 1)
        dp[bit][j] = false;
    }
    REP(j, N - 1)
    {
        dp[0][j] = true;
    }
    dp[0][N - 1] = true;

    REP(bit, (1 << M))
    {
        REP(i, M)
        {
            if (!(bit & (1 << i)))
            {
                int tbit = (bit | (1 << i));
                if (!dp[tbit][N - 1])
                {
                    REP(j, N - 1)
                    {
                        dp[tbit][j] = dp[bit][j];
                    }
                    int a, b;
                    a = query[i].first;
                    b = query[i].second;
                    REP(j, d[a][b].size())
                    {
                        dp[tbit][d[a][b][j]] = false;
                    }
                    dp[tbit][N - 1] = true;
                }
            }
        }
    }
    // REP(i, N)
    // {
    //     REP(j, N)
    //     {
    //         cout << d[i][j].size() << " ";
    //     }
    //     cout << endl;
    // }
    // cout << endl;

    // REP(bit, (1 << M))
    // {
    //     REP(i, N - 1)
    //     {
    //         cout << dp[bit][i] << " ";
    //     }
    //     cout << endl;
    // }

    int ans = 0;
    REP(bit, (1 << M))
    {
        int pm = 0;
        REP(i, M)
        {
            if (bit & (1 << i))
            {
                pm++;
            }
        }
        pm %= 2;
        if (pm == 0)
            pm = 1;
        else
            pm = -1;

        int num = 0;
        REP(i, N - 1)
        {
            if (dp[bit][i])
                num++;
        }
        ans = ans + pm * fn(num);
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 51968