#include<bits/stdc++.h>
using namespace std;
const int N=1e5+10;
int in()
{
	int w=0,f=1;
	char c=getchar();
	while(!isdigit(c))
	{
		if(c=='-') f=-1;
		c=getchar();
	}
	while(isdigit(c))
	{
		w=w*10+c-'0';
		c=getchar();
	}
	return w*f;
}
void out(int w)
{
	if(w<0) 
	{
		putchar('-');
		out(-w);
		return;
	}
	if(w>=10) out(w/10);
	putchar(w%10+'0');
}
struct stu
{
	int v,no;
};
struct stu2
{
	int a1,a2;
};
int c,T,n,k,u,v,e,vis[N],ans;
vector<stu>g[N];
stu2 edge[N];
void dfs(int s,int x)//µ±Ç°µÄ±ß 
{
	if(s==n-1)
	{
		ans++;
		return;
	}
	int b1=edge[x].a1,b2=edge[x].a2;
	for(int i=0;i<g[b1].size();i++)
	{
		int no=g[b1][i].no;
		if(!vis[no])
		{
			vis[no]=1;
			dfs(s+1,no);
			vis[no]=0;
		}
	}
	for(int i=0;i<g[b2].size();i++)
	{
		int no=g[b2][i].no;
		if(!vis[no])
		{
			vis[no]=1;
			dfs(s+1,no);
			vis[no]=0;
		}
	}
}
int main()
{
	freopen("traverse.in","r",stdin);
	freopen("traverse.out","w",stdout);
	c=in();T=in();
	if(c==18) 
	{
		while(T--) 
		{
			out(1);
			putchar('\n'); 
		}
		return 0;
	}
	while(T--)
	{
		ans=0;
		n=in();k=in();
		for(int i=1;i<n;i++) 
		{
			u=in();v=in();
			g[u].push_back({v,i});
			g[v].push_back({u,i});
			edge[i].a1=u;
			edge[i].a2=v;
		}
		while(k--)
		{
			memset(vis,0,sizeof(vis));
			e=in();
			vis[e]=1;
			dfs(1,e);
		}
		out(ans);
		putchar('\n');
	}
	return 0;
 } 
