#include <cstdio>
#include <algorithm>
#include <vector>
#include <cstring>
using namespace std;
typedef pair<int, int> ii;
int N, M, masks[49];
ii uv[20];
long long dptable[1 << 20][49];
vector<ii> adjlist[50];
bool dfs(int v, int p, int mask) {
	if (v == uv[mask].second - 1) return true;
	for (ii i: adjlist[v]) {
		if (i.first == p) continue;
		if (dfs(i.first, v, mask)) {
			masks[i.second] = masks[i.second] | (1 << mask);
			return true;
		}
	}
	return false;
}
long long dp(int i, int j) {
	if (j == N - 1) return i == (1 << M) - 1 ? 1: 0;
	if (dptable[i][j] != -1) return dptable[i][j];
	return dptable[i][j] = (dp(i | masks[j], j + 1) + dp(i, j + 1));
}
int main() {
	memset(dptable, -1, sizeof dptable);
	int a, b;
	scanf("%d", &N);
	for (int i = 1; i < N; ++i) {
		scanf("%d %d", &a, &b);
		adjlist[a - 1].push_back(ii(b - 1, i - 1));
		adjlist[b - 1].push_back(ii(a - 1, i - 1));
	}
	scanf("%d", &M);
	for (int i = 0; i < M; ++i) scanf("%d %d", &uv[i].first, &uv[i].second);
	for (int i = 0; i < M; ++i) dfs(uv[i].first - 1, -1, i);
	printf("%lld", dp(0, 0));
	return 0;
}