#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#define int long long
using namespace std;

const int md=1e9+7;
void read(int &x){
	x=0;
	int f=1;
	char c=getchar();
	while(!('0'<=c && c<='9')){
		if(c=='-'){
			f=-1;
		}
		c=getchar();
	}
	while('0'<=c && c<='9'){
		x=(x<<3)+(x<<1)+(c^48);
		c=getchar();
	}
	x*=f;
}
vector<pair<int,int> > e[100010];
int c,t,n,m,cnt[100010],fact[100010],us[100010],vs[100010],inv[100010],invf[100010],res;
bool is[100010];
void getdpk1(int k,int f){
	for(auto i:e[k]){
		if(i.first!=f){
			getdpk1(i.first,k);
		}
	}
	res=res*fact[((int)e[k].size())-1]%md;
}
signed main(){
	freopen("traverse.in","r",stdin);
	freopen("traverse.out","w",stdout);
	fact[0]=invf[0]=inv[1]=fact[1]=invf[1]=1;
	for(int i=2;i<=100000;i++){
		fact[i]=fact[i-1]*i%md;
		inv[i]=(md-md/i)*inv[md%i]%md;
		invf[i]=invf[i-1]*inv[i]%md;
	}
	read(c);
	read(t);
	while(t--){
		read(n);
		read(m);
		for(int i=1;i<=n;i++){
			e[i].clear();
			is[i]=0;
		}
		int u,v;
		for(int i=1;i<n;i++){
			read(us[i]);
			read(vs[i]);
			e[us[i]].push_back(make_pair(vs[i],i));
			e[vs[i]].push_back(make_pair(us[i],i));
		}
		for(int i=1;i<=m;i++){
			read(u);
			is[u]=1;
		}
		if(c==18){
			printf("1\n");
			continue;
		}
		if(19<=c && c<=21){
			printf("%lld\n",n==2?1:fact[n-1]*inv[2]%md);
			continue;
		}
		if(m==1){
			res=1;
			getdpk1(us[u],vs[u]);
			getdpk1(vs[u],us[u]);
			printf("%lld\n",res);
			continue;
		}
	}
	return 0;
}
