#include<cstdio>
#include<vector>
#include<map>
#include<set>
using namespace std;
const long long mod=1000000007;
int read()
{
	int res=0;
	char c=getchar();
	while(c<'0'||c>'9') c=getchar();
	while(c>='0'&&c<='9')
	{
		res=res*10+c-'0';
		c=getchar();
	}
	return res;
}
int n,k,U[100010],V[100010],ans;
struct edge
{
	int to,id;
};
vector<edge>graph[100010];
map<set<pair<int,int>>,bool>bz;
bool bz_edge[100010];
void search(int now_edge,int chosen,set<pair<int,int>>cur)
{
	if(chosen==n-1)
	{
		if(!bz.count(cur)) bz[cur]=1,ans=(ans+1)%mod;
		return;
	}
	bz_edge[now_edge]=1;
	int point=U[now_edge];
	auto tmp=cur;
	for(auto e:graph[point])
	{
		if(bz_edge[e.id]) continue;
		auto tmp_edge=make_pair(now_edge,e.id);
		if(tmp_edge.first>tmp_edge.second) swap(tmp_edge.first,tmp_edge.second);
		tmp.insert(tmp_edge);
		search(e.id,chosen+1,tmp);
		tmp=cur;
	}
	point=V[now_edge];
	for(auto e:graph[point])
	{
		if(bz_edge[e.id]) continue;
		auto tmp_edge=make_pair(now_edge,e.id);
		if(tmp_edge.first>tmp_edge.second) swap(tmp_edge.first,tmp_edge.second);
		tmp.insert(tmp_edge);
		search(e.id,chosen+1,tmp);
		tmp=cur;
	}
	bz_edge[now_edge]=0;
}
int main()
{
	freopen("traverse.in","r",stdin);
	freopen("traverse.out","w",stdout);
	int c,T;
	c=read();T=read();
	while(T--)
	{
		ans=0;
		bz.clear();
		n=read();k=read();
		for(int i=1;i<n;i++)
		{
			U[i]=read();V[i]=read();
			graph[U[i]].push_back(edge{V[i],i});
			graph[V[i]].push_back(edge{U[i],i});
		}
		for(int i=1;i<=k;i++)
		{
			int e;
			e=read();
			if(c==18) continue;
			for(int j=1;j<n;j++) bz_edge[j]=0;
			search(e,1,set<pair<int,int>>());
		}
		if(c==18) printf("1\n");
		else printf("%d\n",ans);
	}
}