#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<time.h>
#include<random>

using namespace std;

#define REP(i, n) for(int i = 0;i < n;++i)
#define REPR(i, n) for(int i = n-1;i >= 0;--i)
#define FOR(i, m, n) for(int i = m;i < n;++i)
#define FORR(i, m, n) for(int i = m-1;i >= n;--i)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end())
#define ll long long
#define pb(a) push_back
#define print(x) cout<<(x)<<endl
#define pe(x) cout<<(x)<<" "
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define lb(v,n) lower_bound(v.begin(), v.end(), n)
#define ub(v,n) upper_bound(v.begin(), v.end(), n)
#define int long long
#define all(x) (x).begin(), (x).end()
#define print_space(v) REP(i,v.size())cout << v[i] << ((i == v.size() - 1) ? "\n" : " ")
template<typename T1, typename T2> inline void chmin(T1 & a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1& a, T2 b) { if (a < b) a = b; }
typedef pair<int, int>P;
const int MOD = 1e9 + 7; const int MAX = 500050;
const double pi = acos(-1); const double EPS = 1e-12;
const ll INF = 2e18;


double dist(double x1, double x2, double y1, double y2) {
	return sqrt((x1 - x2)*(x1 - x2) + (y1 - y2)*(y1 - y2));
}
double dist(P &p1, P &p2) {
	double x1 = p1.first, x2 = p2.first, y1 = p1.second, y2 = p2.second;
	return sqrt((x1 - x2)*(x1 - x2) + (y1 - y2)*(y1 - y2));
}


vector<int>G[100];
int pa[100];

void make(int n, int pre) {
	for (auto nx : G[n]) {
		if (nx == pre)continue;
		pa[nx] = n;
		make(nx, n);
	}
}
const int MAX_V = 100;
const int MAX_LOG_V = 7;
//vector<int> G[MAX_V];
int root;//根の番号

int parent[MAX_LOG_V][MAX_V];//親を2^k回辿って到達する頂点
int depth[MAX_V];

void dfs(int v, int p, int d) {
	parent[0][v] = p;
	depth[v] = d;
	for (int i = 0; i < G[v].size(); i++) {
		if (G[v][i] != p)dfs(G[v][i], v, d + 1);
	}
}

void init(int V) {
	dfs(root, -1, 0);
	for (int k = 0; k + 1 < MAX_LOG_V; k++) {
		for (int v = 0; v < V; v++) {
			if (parent[k][v] < 0)parent[k + 1][v] = -1;
			else parent[k + 1][v] = parent[k][parent[k][v]];
		}
	}
}

int lca(int u, int v) {
	if (depth[u] > depth[v]) {
		swap(u, v);
	}
	for (int k = 0; k < MAX_LOG_V; k++) {
		if ((depth[v] - depth[u]) >> k & 1) {
			v = parent[k][v];
		}
	}
	if (u == v)return u;
	for (int k = MAX_LOG_V - 1; k >= 0; k--) {
		if (parent[k][u] != parent[k][v]) {
			u = parent[k][u];
			v = parent[k][v];
		}
	}
	return parent[0][u];
}
int memo[101];
unordered_set<int>st[101];
unordered_set<int> dfs2(int n, int pre) {
	if (st[n].size() != 0)return st[n];
	st[n].insert(n);
	for (auto nx : G[n]) {
		if (nx == pre)continue;
		unordered_set<int>st2 = dfs2(nx, n);
		for (auto x : st2)st[n].insert(x);
	}
	return st[n];
}
int deg[101];

int cnt[1 << 20];
int us[101], vs[101];
int tmp[1 << 20];

void solve() {
	int N; cin >> N;
	vector<P>es(N - 1);
	REP(i, N - 1) {
		int u, v; cin >> u >> v; u--,v--;
		G[u].push_back(v);
		G[v].push_back(u);
		deg[u]++; deg[v]++;
		es[i] = { u,v };
	}
	int M; cin >> M;

	REP(i, M) {
		int u, v; cin >> u >> v; u--, v--;
		us[i] = u; vs[i] = v;
	}
	root = 0;
	init(N);
	make(0, 0);
	//dfs2(0, 0);
	cnt[0] = 1;
	int pos = 0;
	vector<int>bits(N);
	REP(i, N-1) {

		int u = es[i].first, v = es[i].second;
		int nxtbit = 0;
		REP(j, M) {
			int p = us[j], q = vs[j];
			int par = lca(p, q);
			if (lca(par, u) == par && lca(par, v) == par && ((lca(u, p) == u && lca(v, p) == v) || (lca(v, q) == v && lca(u, q) == u)))nxtbit |= (1 << j);
		}
		bits[i] = nxtbit;
	}
	REP(i, N - 1) {
		REP(j, 1 << M)tmp[j] = 0;
		REP(bit, 1 << M) {
			tmp[bit|bits[i]] += cnt[bit];
		}
		REP(j, 1 << M)cnt[j] += tmp[j];
	}
	//REP(i, N-1) {
	//	int nxt = pos ^ 1;
	//	int u = es[i].first, v = es[i].second;
	//	REP(j, 1 << M)tmp[j] = 0;
	//	REP(bit, 1 << M) {


	//		int nxtbit = bit;
	//		REP(j, M) {
	//			int p = us[j], q = vs[j];
	//			int par = lca(p, q);
	//			if (lca(par, u) == par && lca(par, v) == par&&((lca(u,p)==u&&lca(v,p)==v)||(lca(v,q)==v&&lca(u,q)==u)))nxtbit |= (1 << j);
	//		}
	//		tmp[nxtbit] += cnt[bit];
	//	}
	//	REP(j, 1 << M)cnt[j] += tmp[j];
	//}
	print(cnt[(1 << M) - 1]);
}

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	//int q;cin>>q;
	//while(q--)
	solve();
}




Measured memory_bytes: 16768