#include<cstdio>
#include<cstring>
#define N 100005
#define K 1000000007
#define ll long long
using namespace std;
int n,ok[105],vis[N],num[105],c,t,k,k2=1,u,v,h[N],id[N],moshi,cnt2[15],num2;
ll f[N];
ll ans;
struct bian{
	int s,e,n;
}a[200005];
void add(int u,int v){
	a[++k2].s=u,a[k2].e=v,a[k2].n=h[u],h[u]=k;
}
int lin(int u,int v){
	int k3=(u<<1),k4=(v<<1);
	if(a[k3].s == a[k4].s || a[k3].s == a[k4].e) return 1;
	if(a[k3].e == a[k4].s || a[k3].e == a[k4].e) return 1;
	return 0;
}
int judge(){
	for(int i=1;i<n;i++) if(!vis[i]) return 0;
	return 1;
}
inline int read(){
	char ch=getchar();
	int x=0;
	while(ch < '0' || ch > '9') ch=getchar();
	while(ch >= '0' && ch <= '9') x=(x<<3)+(x<<1)+(ch^48),ch=getchar();
	return x;
}
int main(){
	freopen("traverse.in","r",stdin);
	freopen("traverse.out","w",stdout);
	scanf("%d%d",&c,&t);
	f[0]=1;
	for(int i=1;i<=100000;i++) f[i]=(ll)f[i-1]*i%K;
	while(t--){
		n=read(),k=read();
		k2=1;
		memset(h,0,sizeof(h));
		for(int i=1;i<n;i++){
			u=read(),v=read();
			add(u,v),add(v,u);
		}
		for(int i=1;i<=k;i++){
			id[i]=read();
		}
		if(c == 18){
			printf("1\n");
			continue;
		}
		if(c >= 19 && c <= 21){
			ans=(ll)k*(((ll)k-1)*f[n-1-2]%K*(K+1>>1)%K+((ll)n-1-k)*f[n-1-2]%K)%K;
			printf("%lld\n",ans);
		}
		if(c <= 6){
			for(int i=1;i<n;i++){
				cnt2[i]=0;
				for(int j=1;j<n;j++){
					if(lin(i,j) && j != i) ++cnt2[i];
				}
				--cnt2[i];
			}
			++cnt2[id[1]];
			ans=1;
			for(int i=1;i<n;i++) if(cnt2[i]) ans=(ll)ans*cnt2[i]%K;
			if(ans > 2) ans=2;
			printf("%lld\n",ans);
		}
	}
	return 0;
}
/*
1 1
5 2
1 2
1 3
2 4
2 5
1 3
*/
