#include<bits/stdc++.h>
#define mod 1000000007
#define int long long
using namespace std;
int c,t,n,k,e[100005],now,u[100005],v[100005],f[100005][3],fa[100005],id[100005],sz[100005],d[100005],cnt,ans,fac[100005];
vector<int>ve[100005];
void dfs(int u,int f){
	fa[u]=f,id[u]=++cnt,sz[u]=1;
	for(int v:ve[u]){
		if(v==f)continue;
		dfs(v,u),sz[u]+=sz[v];
	}
}
void dfs2(int u,int f,int p){
	int cnt=0,dd=ve[u].size();
	if(p-(d[id[u]+sz[u]-1]-d[id[u]])>0)cnt++;
	for(int v:ve[u]){
		if(v==f)continue;
		dfs2(v,u,p);
		if(d[id[v]+sz[v]-1]-d[id[v]-1]>0)cnt++;
	}
	if(dd==1)return;
	if(cnt>=3)now=0; 
	else if(cnt==1)now*=dd-1,now%=mod;
	else if(cnt==0)now*=(dd-1)*(dd-2)/2,now%=mod;
}
signed main(){
	freopen("traverse.in","r",stdin);
	freopen("traverse.out","w",stdout); 
	ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	cin>>c>>t,fac[0]=1;
	for(int i=1;i<=1e5;i++)fac[i]=fac[i-1]*i%mod;
	while(t--){
		cin>>n>>k,cnt=0,ans=0;
		for(int i=1;i<=n;i++)ve[i].clear(),d[i]=0;
		for(int i=1;i<=n;i++)for(int j=0;j<3;j++)f[i][j]=0;
		int flag=1; 
		for(int i=1;i<n;i++)cin>>u[i]>>v[i],ve[u[i]].emplace_back(v[i]),ve[v[i]].emplace_back(u[i]);
		for(int i=1;i<n;i++)flag&=u[i]==i&&v[i]==i+1;
		if(flag){cout<<"1\n";continue;}
		dfs(1,0);
		for(int i=1;i<=k;i++){
			cin>>e[i];
		}
		for(int i=1;i<(1<<k);i++){
			for(int j=1;j<=n;j++)d[j]=0;
			now=1;
			for(int j=1;j<=k;j++)if(i&(1<<j-1)){
				if(fa[u[e[j]]]==v[e[j]])d[id[u[e[j]]]]++;
				else d[id[v[e[j]]]]++;
			}
			for(int j=1;j<=n;j++)d[j]+=d[j-1];
			dfs2(1,0,__builtin_popcount(i));
			if(__builtin_popcount(i)&1)ans+=now;
			else ans-=now;
			ans+=mod,ans%=mod;
		}
		for(int i=1;i<=n;i++){
			int dd=ve[i].size();
			if(dd>2)ans*=fac[dd-2],ans%=mod;
		}
		cout<<ans<<"\n";
	}
	return 0;
}
