#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
const int M = 2e5+ 5;
vector<int>road[N];
struct node{
	int u,v;
}e[N];
int head[N];
int nxt[M],to[M];
int id;
void add(int x,int y)
{
	id++;
	nxt[id] = head[x];
	head[x] = id;
	to[id] = y;
}
bool flag[N];
int n,k;
int dfs(int u,int cnt)
{
//	cout << u << " " << cnt << endl;
	if(cnt == n - 1)return 1;
	int ans = 0;
	for(int i = head[u];i;i = nxt[i])
	{
		int v = to[i];
		if(!flag[v])
		{
			flag[v] = true;
			ans += dfs(v,cnt + 1);
			flag[v] = false;
		}
	}
	return ans;
}
int main()
{
	freopen("traverse.in","r",stdin);
	freopen("traverse.out","w",stdout);
	int c,t;
	cin >> c >> t;
	while(t--)
	{
		cin >> n >> k;
		for(int i = 1;i < n;i++)
		{
			int u,v;
			cin >> u >> v;
			road[u].push_back(v);
			road[v].push_back(u);
			e[i].u = u;
			e[i].v = v;	
		}
		for(int i = 1;i < n;i++)
		{
			for(int j = 1;j < n;j++)
			{
				if(i == j)continue;
				if(e[i].u == e[j].u || e[i].u == e[j].v || e[i].v == e[j].u || e[i].v == e[j].v)
				{
					add(i,j);
					add(j,i);
				}
			}
		}
		int ans = 0;
		for(int i = 1;i <= k;i++)
		{
			int u;
			cin >> u;
		}
		cout << dfs(1,1) << endl;
	}
	return 0;
}
