#include<bits/stdc++.h>
#define ll long long
#define pb push_back
using namespace std;
const int N=200005,mod=1e9+7;
int n,m,k,id[N],d[N],b[N];
ll ans,fac[N],dp[N],f[N];
vector<int> g[N];
int add(int x,int y){x+=y;if(x>=mod)x-=mod;return x;}
int sub(int x,int y){x-=y;if(x<0)x+=mod;return x;}
void dfs(int u,int fa){
	int c=0;f[u]=1,dp[u]=0;
	for(int v:g[u])if(v!=fa)dfs(v,u),c++,f[u]=f[u]*f[v]%mod;
	if(u>n){
		if(c==1){
			for(int v:g[u])if(v!=fa)dp[u]=dp[v];
		}else{
			int v1=0,v2=0;
			for(int v:g[u])if(v!=fa){
				if(!v1)v1=v;
				else v2=v;
			}
//			cerr<<v1<<' '<<v2<<' '<<dp[v1]<<' '<<dp[v2]<<'\n';
			dp[u]=add(dp[v1]*f[v2]%mod,sub(f[v1]*dp[v2]%mod,dp[v1]*dp[v2]%mod));
		}
		if(b[u-n])dp[u]=f[u];
		return;
	}
	f[u]=f[u]*fac[c]%mod;
	ll F[2]={fac[c-1],0};
	for(int v:g[u])if(v!=fa)F[1]=add(F[1]*f[v]%mod,F[0]*dp[v]%mod),F[0]=F[0]*f[v]%mod;
	dp[u]=F[1];
}
void solve(int opt){
	cin>>n>>m,k=(n<<1)-1,ans=0,fac[0]=1;
	for(int i=1;i<=k;i++)d[i]=0,fac[i]=fac[i-1]*i%mod,g[i].clear(),b[i]=0;
	for(int i=1,x,y;i<n;i++)cin>>x>>y,g[x].pb(n+i),g[n+i].pb(x),g[y].pb(n+i),g[n+i].pb(y),d[x]++,d[y]++;
	for(int i=1;i<=m;i++)cin>>id[i];
	if(opt==18){
		cout<<"1\n";
		return;
	}else if(opt>=19&&opt<=21){
		for(int i=1;i<=m;i++)ans=add(ans,fac[n-2]*(n-i)%mod);
		cout<<ans<<'\n';
		return;
	}
	for(int i=1;i<=m;i++)dfs(id[i]+n,0),b[id[i]]=1,ans=add(ans,sub(f[id[i]+n],dp[id[i]+n]));
	cout<<ans<<'\n';
}
int main(){
	freopen("traverse.in","r",stdin);
	freopen("traverse.out","w",stdout);
	ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	int o,T;cin>>o>>T;while(T--)solve(o);
	return 0;
}
