#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long ll;
inline ll read(){
	ll x=0;
	int c=getchar();
	bool f=0;
	while(c<48||c>57) f=(c=='-'),c=getchar();
	while(c>47&&c<58) x=(x<<3)+(x<<1)+(c&15),c=getchar();
	return f?-x:x;
}
inline void write(ll x,char end='\n'){
	if(x==0){
		putchar('0');
		putchar(end);
		return;
	}
	if(x<0) putchar('-'),x=-x;
	short ch[30]={0},cnt=0;
	while(x) ch[cnt++]=x%10,x/=10;
	while(cnt--) putchar(ch[cnt]^48);
	putchar(end);
}
const ll mod=1e9+7;
const int N=1e5+5;
int n,k;
struct node{
	int to,nxt,id;
}e[N<<1];
int head[N],cnt;
inline void add(int u,int v,int id){
	e[++cnt]={v,head[u],id};
	head[u]=cnt;
}
int ed[N];
int lft[N],rgt[N];
inline void getinput(){
	n=read(),k=read();
	for(int i=1,u,v;i<n;++i){
		u=read(),v=read();
		add(u,v,i),add(v,u,i);
		lft[i]=u,rgt[i]=v;
	}
	for(int i=1;i<=k;++i) ed[i]=read();
}
inline void clr(){
	for(int i=1;i<=n;++i) head[i]=0;
	cnt=0;
}
inline void solve(){
	puts("1");
}
ll fac[N];
inline void init(){
	fac[0]=1;
	for(int i=1;i<N;++i) fac[i]=fac[i-1]*i%mod;
}
inline void solvechain(){
	puts("1");
}
inline void solveflower(){
	ll ans=0;
	for(int i=1;i<=k;++i){
		ans+=fac[n-2]-(n>=3?(i-1)*fac[n-3]%mod:0);
		ans%=mod;
	}
	ans=(ans+mod)%mod;
	write(ans);
}
ll prodfac[N];
inline void dfs1(int u,int fromed){
	prodfac[u]=1;
	int son=0;
	for(int i=head[u];i;i=e[i].nxt){
		if(e[i].id==fromed) continue;
		int v=e[i].to;
		dfs1(v,e[i].id);
		++son;
		prodfac[u]=prodfac[u]*prodfac[v]%mod;
	}
	prodfac[u]=prodfac[u]*fac[son]%mod;
}
inline void solveke1(){
	int ued=ed[1];
	dfs1(lft[ued],ued);
	dfs1(rgt[ued],ued);
	write(prodfac[lft[ued]]*prodfac[rgt[ued]]%mod);
}
int main(){
	freopen("traverse.in","r",stdin);
	freopen("traverse.out","w",stdout);
	init();
	int c=read(),T=read();
	while(T--){
		getinput();
		if(c>=1&&c<=6) solveke1();
		else if(c==18) solvechain();
		else if(c>=19&&c<=21) solveflower();
		else solve();
		clr();
	}
	return 0;
}
