#include<bits/stdc++.h>
#define pb push_back
#define ll long long
using namespace std;
const int N=1e5+5,p=1e9+7;
int n,k,q;
vector<int> g[N];
ll powr(ll x,ll y){
	ll s=1;
	while(y>0){
		if(y%2==1) s*=x,s%=p;
		x*=x;x%=p;y/=2;
	}
	return s;
}
ll fac[N],d[N];
int u[N],v[N];
int c,t;
ll ans=1;
void dfs(int x,int fa){
	int siz=0;
	for(int y:g[x]){
		if(y==fa) continue;
		dfs(y,x);
		siz++;
	}
	ans*=fac[siz];ans%=p;
}
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;
	fac[0]=1;
	ll inv2=(p-p/2);
	for(int i=1;i<=1e5;i++)
		fac[i]=fac[i-1]*i%p;
	while(t--){
		cin>>n>>k;
		for(int i=1;i<=n;i++)
			g[i].clear();
		for(int i=1;i<n;i++){
			cin>>u[i]>>v[i];
			g[u[i]].pb(v[i]);
			g[v[i]].pb(u[i]);
		}
		for(int i=1;i<=k;i++)
			cin>>d[i];
		if(c==18) {cout<<1<<"\n";continue;}
		if(19<=c && c<=21){
			ll s=fac[n-1];
			ll ss=n-k-1;
			s-=(ss*(ss-1))%p*fac[n-3]%p;
			s*=inv2;
			cout<<(s%p+p)%p<<"\n";
			continue;
		}
		ans=1;
		dfs(u[d[1]],v[d[1]]);
		dfs(v[d[1]],u[d[1]]);
		cout<<ans<<"\n";
	}
	return 0;
} 
