#include <bits/stdc++.h>

using namespace std;

int n, m, x[55];
vector<pair<int, int>> v[55];
long long dp[1 << 20];

bool dfs1(int a, int b, int c, int d) {
	if (a == c)
		return 1;
	for (auto& i : v[a])
		if (i.first != b && dfs1(i.first, a, c, d)) {
			x[i.second] ^= 1 << d;
			return 1;
		}
	return 0;
}

void dfs2(int a, int b) {
	
}

int main() {
	scanf("%d", &n);
	for (int i = 1; i < n; i++) {
		int ta, tb;
		scanf("%d%d", &ta, &tb);
		v[ta].emplace_back(tb, i);
		v[tb].emplace_back(ta, i);
	}
	scanf("%d", &m);
	for (int i = 0; i < m; i++) {
		int ta, tb;
		scanf("%d%d", &ta, &tb);
		dfs1(ta, 0, tb, i);
	}
	dp[0] = 1;
	// for (int i = 1; i < n; i++) printf("x[%d]=%d\n", i, x[i]);
	for (int i = 1; i < n; i++)
		for (int j = (1 << m) - 1; j >= 0; j--)
			dp[j | x[i]] += dp[j];
	printf("%lld\n", dp[(1 << m) - 1]);
}