#include <bits/stdc++.h>
#define ll long long

using namespace std;

const ll N = 2e3, mod = 1e9 + 7;

struct edge {
	ll u, v;
} e[N + 5];
struct Edge {
	ll nxt, to;
} E[2 * N * N + 5];
ll n, k, head[N + 5], tot, ans;
bool bz[N + 5];

void add(ll u, ll v) {
	E[++tot] = {head[u], v};
	head[u] = tot;
}

void dfs(ll x, int t) {
	if (t == n - 1) {
		ans++;
		return;
	}
	bz[x] = true;
	for (ll i = head[x]; i; i = E[i].nxt) {
		if (bz[E[i].to]) continue;
		dfs(E[i].to, t + 1);
	}
	bz[x] = false;
}

int main() {
	freopen("traverse.in", "r", stdin);
	freopen("traverse.out", "w", stdout);
	ll c, T; scanf("%lld%lld", &c, &T);
	while (T--) {
		scanf("%lld%lld", &n, &k);
		for (ll i = 1; i < n; i++)
			scanf("%lld%lld", &e[i].u, &e[i].v);
		if (c == 18) {
			puts("1");
			continue;
		}
		tot = 0;
		for (ll i = 1; i < n; i++) {
			for (ll j = i + 1; j < n; j++) {
				if (e[i].u == e[j].v || e[i].u == e[j].u || e[i].v == e[j].u || e[i].v == e[j].v) 
					add(i, j), add(j, i);
			}
		}
		int Ans = 0;
		for (ll i = 1; i <= k; i++) {
			ll x; scanf("%lld", &x);
			ans = 0;
			memset(bz, 0, sizeof bz);
			dfs(x, 1);
			Ans += ans;
		}
		printf("%d\n", Ans);
	}
}
