#include<bits/stdc++.h>
using namespace std;
int c,Tn,n,k,u[100010],v[100010],vis[100010];
const long long Mod = 1e9+7;
long long ans;
vector<int> ma[100010];
void dfs(int x)
{
	int s = 0;
	for(int i=1;i<=n;i++)
		s += vis[i];
	if(s==n-1)
	{
		ans++;
		return;
	}
	for(auto t:ma[x])
	{
		if(vis[t])
			continue;
		vis[t] = 1;
		dfs(t);
		vis[t] = 0;
	}
}
int main()
{
	freopen("traverse.in","r",stdin);
	freopen("traverse.out","w",stdout);
	
	scanf("%d%d",&c,&Tn);
	
	while(Tn--)
	{
		scanf("%d%d",&n,&k);
		for(int i=1;i<n;i++)
			scanf("%d%d",&u[i],&v[i]);
			
		for(int i=1;i<n;i++)
		{
			for(int j=1;j<n;j++)
			{
				if(j==i)
					continue;
				if(u[i]==u[j] || u[i]==v[j] || v[i]==u[j] || v[i]==v[j] )
					ma[i].push_back(j);
			}
		}
		for(int i=1;i<n;i++)
		{
			for(int t:ma[i])
				cout<<t<<" ";
			cout<<endl;
		}
		ans = 0 ;
		for(int i=1,x;i<=k;i++)
		{
			scanf("%d",&x);
			vis[x] = 1;
			dfs(x);
			vis[x] = 0;
		}
		printf("%lld",ans);
	}
	
	return 0;
} 
