#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<vector>
using namespace std;
typedef long long ll;
int re(){
	int a=0;bool f=1;
	char ch=getchar();
	for(;ch<'0'||ch>'9';ch=getchar())
		if(ch=='-') f=0;
	for(;ch>='0'&&ch<='9';ch=getchar())
		a=(a<<3)+(a<<1)+(ch^48);
	return f? a:-a;
}

const int M=1e5+5;
const ll mod=1e9+7;
struct node{
	int x,y;
	int id;
	vector<pair<int,int> > g;
}tr[M];
vector<pair<int,int> >pnt[M];

ll fac(int n){
	ll ans=1ll;
	for(int i=1;i<=n;++i){
		ans*=1ll*i;
		if(ans>mod) ans%=mod;
	}
	return ans;
}
void dfsp(int x,int fa){
	int len=pnt[x].size(),lenson;
	for(int i=0,y,w;i<len;++i){
		y=pnt[x][i].first;
		w=pnt[x][i].second;
		tr[w].x=x;tr[w].y=y;
		lenson=pnt[y].size();
		for(int j=0;j<lenson;++j){
			if(pnt[y][j].second!=w)
				tr[w].g.push_back(make_pair(pnt[y][j].second,y));
		}
		if(y!=fa) dfsp(y,x);
	}
}
ll dfse(int x,int fapnt){
	ll ans1=0ll,ans2=0ll;
	int len=tr[x].g.size();
	int F=tr[x].g[0].second;
	for(int i=0,y,w;i<len;++i){
		y=tr[x].g[i].first;
		w=tr[x].g[i].second;
		if(w!=fapnt){
			if(w!=F) ++ans1;
			else ++ans2;
		}
	}
	if(!ans1) ans1=1;
	if(!ans2) ans2=1;
	ans1=fac(ans1);
	ans2=fac(ans2);
	for(int i=0,y,w;i<len;++i){
		y=tr[x].g[i].first;
		w=tr[x].g[i].second;
		if(w!=fapnt){
			if(w!=F){
				ans1*=fac(dfse(y,w));
				ans1%=mod;
			}else{
				ans2*=fac(dfse(y,w));
				ans2%=mod;
			}
		}
	}
	return (ans1*ans2)%mod;
}

int main(){
	freopen("traverse.in","r",stdin);
	freopen("traverse.out","w",stdout);
	int c=re(),T=re(),n,k;
	while(T--){
		n=re(),k=re();
		for(int i=1;i<=n;++i){
			pnt[i].clear();
			tr[i].g.clear();
		}
		for(int i=1,u,v;i<n;++i){
			u=re(),v=re();
			tr[i].id=i;
			tr[i].x=u;tr[i].y=v;
			pnt[u].push_back(make_pair(v,i));
			pnt[v].push_back(make_pair(u,i));
		}
		if(c==18){
			printf("1\n");
		}else if(c>=19&&c<=21){
			printf("%lld\n",(1ll*k*fac(n-2))%mod);
		}else{
			if(k==1){
				int root=re();
				dfsp(root,0);
				cout<<dfse(root,0)<<"\n";
			}else{
				int root;
				for(int i=1,r;i<=k;++i){
					r=re();
					if(i==1) root=r;
				}
				dfsp(root,0);
				cout<<(1ll*k*dfse(root,0)-(k-1ll))%mod<<"\n";
			}	
		}
	}
	fclose(stdin);
	fclose(stdout);
	return 0;
}
