#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define rg register
#define fo(i,l,r) for(rg int i(l);i<=(r);++i)
#define rp(i,l,r) for(rg int i(r);i>=(l);--i)
#define pb push_back
#define pc putchar
#define gc getchar
using namespace std;

const int N=1e5+5;
const int mod=1e9+7;

int Id,T,n,k;
int u[N<<1],v[N<<1],e[N];
int tot,final[N],nt[N<<1],to[N<<1];
int fac[N],fa[N];

inline int re() {
	rg int x=0,p=1;rg char c=gc();
	while(!isdigit(c)) {
		if(c=='-') p=-1;
		c=gc();
	}
	while(isdigit(c)) (x*=10)+=c-48,c=gc();
	return x*p;
}
inline void wt(rg int x) {
	if(x<0) pc('-'),x=-x;
	if(x>9) wt(x/10);
	pc(x%10+48);
}

int qp(int a,int b=mod-2) {
	int s=1;while(b) {
		if(b&1) s=1ll*s*a%mod;
		a=1ll*a*a%mod;b>>=1;
	} return s;
}
void link(int x,int y) {
	to[++tot]=y;
	nt[tot]=final[x];
	final[x]=tot;
}
void dfs(int x,int f) {
	fa[x]=f;
	for(int i=final[x];i;i=nt[i]) {
		int y=to[i];
		if(y!=f) {
			dfs(y,x);
		}
	}
}

namespace k1 {
	int d[N];
	void Main() {
		fo(i,1,n-1) {
			d[u[i]]++,d[v[i]]++;
		}
		int ans=1;
		fo(i,1,n) {
			ans=1ll*ans*fac[d[i]-1]%mod;
		}
		wt(ans),pc('\n');
		
		fo(i,1,n) d[i]=0;
	}
}

namespace k2 {
	int d[N];
	void Main() {
		fo(i,1,n-1) {
			d[u[i]]++,d[v[i]]++;
		}
		int ans=1;
		fo(i,1,n) {
			ans=1ll*ans*fac[d[i]-1]%mod;
		}
		d[fa[e[1]]]--;
		fo(i,1,n) {
			ans=1ll*ans*fac[d[i]-1]%mod;
		}
		wt(ans),pc('\n');
		
		fo(i,1,n) d[i]=0;
	}
}


int main() {
	freopen("traverse.in","r",stdin);
	freopen("traverse.out","w",stdout);
	fac[0]=1;fo(i,1,100000) fac[i]=1ll*fac[i-1]*i%mod;
	scanf("%d%d",&Id,&T);
	while(T--) {
		n=re(),k=re();
		tot=0;fo(i,1,n) final[i]=0;
		fo(i,1,n-1) {
			u[i]=re(),v[i]=re();
			link(u[i],v[i]);
			link(v[i],u[i]);
		}
		dfs(1,0);
		fo(i,1,k) {
			e[i]=re();
		}
		if(n<=2) {
			puts("1");
			continue;
		}
		if(Id<=6) {
			k1::Main();
			continue;
		}
		if(Id==18) {
			puts("1");
			continue;
		}
		if(19<=Id&&Id<=21) {
			int ans=fac[n-1];
			ans=1ll*ans*qp(2)%mod;
			ans=(ans-1ll*(n-1-k)*(n-1-k-1)/2%mod*fac[n-3]%mod+mod)%mod;
			wt(ans),pc('\n');
			continue;
		}
		k2::Main();
	}
}
