#include <bits/stdc++.h> 
using namespace std;
const int INF = 0x3f3f3f3f;
const int N = 1e5 + 10;
struct node{
	int data;
	int to;
	int next;
} edge[N];
int head[N], len;
void add(int x, int y, int num)
{
	edge[++len].data = num;
	edge[len].to = y;
	edge[len].next = head[x];
	head[x] = len;
}
int c, T;
int n, k;
int u[N], v[N];
bool vis[N];
int ans;
map<string, int> mp;
bool check_finish()
{
	for(int i = 1;i <= n;i ++)
	{
		if(!vis[i]) return false;
	}
	return true;
}
string make(string s, int x)
{
	string y = "";
	string ss = s;
	while(x)
	{
		int xx = x % 10;
		y += x - '0';
		x /= 10;
	}
	for(int i = y.size() - 1;i >= 0;i --)
	{
		ss += y[i];
	}
	return ss;
}
void dfs(int pos, string route)
{
	if(check_finish())
	{
		if(!mp[route])
		{
			mp[route] ++;
			ans ++;
		}
		return ;
	}
	for(int i = head[pos]; i; i = edge[i].next)
	{
		if(vis[edge[i].to]) continue ;
		vis[edge[i].to] = 1;
		dfs(edge[i].to, make(route, edge[i].data));
		vis[edge[i].to] = 0;
	}
}
int main(){
	freopen("traverse.in", "r", stdin);
	freopen("traverse.out", "w", stdout);
	cin >> c >> T;
	while(T--)
	{
		cin >> n >> k;
		for(int i = 1;i < n;i ++)
		{
			cin >> u[i] >> v[i];
			add(u[i], v[i], i);
			add(v[i], u[i], i);
		}
		for(int i = 1;i <= k;i ++)
		{
			memset(vis, 0, sizeof(vis));
			int x;
			cin >> x;
			vis[x] = 1;
			dfs(v[x], "");
		}
		cout << ans << endl;
	}
	return 0;
}

