#include<iostream>
#include<vector>
#define ll long long
using namespace std;
const int N=1e5+5;
const ll mod=1e9+7;
int T,c,n,k;
int f[N],nxt[N<<1],to[N<<1],cnt,deg2[N];
ll dp[N],deg[N],ans,tmp;
bool mrk[N<<1];
void add(int u,int v){nxt[++cnt]=f[u];f[u]=cnt;to[cnt]=v;}
void dfs1(int u,int fa){
	if(deg2[fa])++deg2[u];
	for(int i=f[u],v;i;i=nxt[i]){
		v=to[i];
		if(v==fa)continue;
		if(mrk[i])++deg2[u];
		dfs1(v,u);
		if(!mrk[i]&&deg2[v]>1)++deg2[u];
	}
}
void dfs2(int u,int fa){
	if(deg[u]==3)dp[u]=2;
	else if(deg[u]>3)dp[u]=deg[u]*(deg[u]-1)/2%mod;
	else dp[u]=1;
	for(int i=f[u],v;i;i=nxt[i]){
		v=to[i];
		if(v==fa)continue;
		dfs2(v,u);
		dp[u]=dp[u]*dp[v]%mod;
	}
}
void solve(){int x,y;
	cin>>n>>k;
	cnt=1;
	for(int i=1;i<=n;++i)f[i]=deg[i]=deg2[i]=mrk[i<<1]=mrk[i<<1|1]=0;
	for(int i=1;i<n;++i){
		cin>>x>>y;
		add(x,y);
		add(y,x);
		++deg[x];
		++deg[y];
	}
	for(int i=1;i<=k;++i){
		cin>>x;
		mrk[x<<1]=mrk[x<<1|1]=1;
	}
	if(c==18){
		cout<<"1\n";
		return;
	}
	dfs1(1,0);
	dfs2(1,0);
	ans=dp[1];
	for(int i=1;i<=n;++i)
		if(deg[i]==3&&deg2[i]>1)++tmp;
	if(tmp>1)--tmp;
	(ans+=tmp*(mod+1>>1)%mod*dp[1]%mod)%=mod;
	cout<<ans<<endl;
}
int 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;
	while(T--)solve();
	return 0;
}
