#include<bits/stdc++.h>
using namespace std;
const int N = 1e6 + 10,mod = 1e9 + 7;
int idx1,nxt1[N],d1[N],h1[N];
int idx,nxt[N],d[N],h[N];
int dp[N],vis[N];
int c,T,n,k,ans;
void add1(int x,int y)
{
	idx1++;
	d1[idx1] = y;
	nxt1[idx1] = h1[x];
	h1[x] = idx1;
}
void add(int x,int y)
{
	idx++;
	d[idx] = y;
	nxt[idx] = h[x];
	h[x] = idx;
}
void dfs(int x,int dep)
{
	if(dep > n)
	{
		ans++;
		return;
	}
	vis[x] = 1;
	for(int i = h[x];i;i = nxt[i])
		if(!vis[d[i]])
			dfs(d[i],dep + 1);
}
int main()
{
	freopen("traverse.in","r",stdin);
	freopen("traverse.out","w",stdout);
	cin >> c >> T;
	srand(time(0));
	int t,t1;
	while(T--)
	{
		cin >> n >> k;
		for(int i = 1;i <= n;i++)
			dp[i] = 0;
		for(int i = 1;i < n;i++)
		{
			cin >> t >> t1;
			add1(t,t1);
			add1(t1,t);
		}
		for(int i = 1;i <= n;i++)
			for(int u = h1[i];u;u = nxt1[u])
				for(int o = h1[i];o;o = nxt1[o])
					if(u != o)
						add(u,o),add(o,u);
		for(int i = 1;i <= k;i++)
		{
			cin >> t;
			for(int u = 1;u <= n;u++)
				vis[u] = dp[i] = 0;
//			dp[t]++;
			dfs(t,1);
//			ans += ma; 
		}
			cout << ans << '\n';
//		cout << rand() % mod << '\n';
	}
	return 0;
}
