#include<bits/stdc++.h>
using namespace std;
namespace my_std{
	#define ll long long
	#define bl bool
	#define fr(i,x,y) for(ll i=(x);i<=(y);i++)
	#define pfr(i,x,y) for(ll i=(x);i>=(y);i--)
	#define go(u) for(ll i=head[u];i;i=e[i].nxt)
	#define il inline
	#define db double
	#define pf printf
	#define pc putchar
	#define MP make_pair
	#define fir first
	#define sec second
	#define space pc(' ')
	#define enter pc('\n')
	il ll read(){
		ll sum=0,fu=0;
		char ch=getchar();
		while(!isdigit(ch)){
			if(ch=='-') fu=1;
			ch=getchar();
		}
		while(isdigit(ch)){
			sum=sum*10+(ch-'0');
			ch=getchar();
		}
		return fu?(-sum):sum;
	}
	void write(ll x){
		if(x<0){
			pc('-');
			x=-x;
		}
		if(x>9) write(x/10);
		pc('0'+(x%10));
	}
	il void writesp(ll x){
		write(x);
		space;
	}
	il void writeln(ll x){
		write(x);
		enter;
	}
}
using namespace my_std;
#define mod 1000000007
ll c,t,n,k,head[100010],cnt=0,all=1;
ll d[100010],dep[100010],f[100010],g[100010][2];
ll jc[100010],jcinv[100010],invv[100010];
bl ck[100010];
struct edge{
	ll u,v;
}E[100010];
struct node{
	ll nxt,to;
}e[200020];
il void add(ll u,ll v){
	e[++cnt].nxt=head[u];
	e[cnt].to=v;
	head[u]=cnt;
}
il ll my_pow(ll x,ll y){
	ll res=1;
	while(y){
		if(y&1) res=res*x%mod;
		x=x*x%mod;
		y>>=1;
	}
	return res;
}
void dfs0(ll fa,ll u){
	dep[u]=dep[fa]+1;
	go(u){
		ll v=e[i].to;
		if(v==fa) continue;
		dfs0(u,v);
	}
}
void dfs(ll fa,ll u){
	ll sum1=0,sum2=0;
	go(u){
		ll v=e[i].to;
		if(v==fa) continue;
		dfs(u,v);
		f[u]=(f[u]+sum1*(g[v][0]+g[v][1]))%mod;
		f[u]=(f[u]-sum2*g[v][0]%mod+mod)%mod;
		if(!ck[u]) g[u][0]=(g[u][0]+g[v][0])%mod;
		else g[u][1]=(g[u][1]+g[v][0])%mod;
		g[u][1]=(g[u][1]+g[v][1])%mod;
		sum1=(sum1+g[v][0]+g[v][1])%mod;
		sum2=(sum2+g[v][0])%mod;
	}
	if(d[u]==1){
		if(fa) g[u][ck[u]]=1;
		else f[u]=(f[u]+g[u][1])%mod;
	}
	else{
		ll tmp=invv[d[u]-1];
		f[u]=f[u]*tmp%mod;
		g[u][0]=g[u][0]*tmp%mod;
		g[u][1]=g[u][1]*tmp%mod;
	}
	go(u){
		ll v=e[i].to;
		if(v==fa) continue;
		f[u]=(f[u]+f[v])%mod;
	}
}
il void clr(){
	fr(i,1,n) head[i]=d[i]=dep[i]=f[i]=g[i][0]=g[i][1]=ck[i]=0;
	cnt=0;
	all=1;
}
int main(){
	freopen("traverse.in","r",stdin);
	freopen("traverse.out","w",stdout);
	c=read();
	t=read();
	while(t--){
		n=read();
		k=read();
		fr(i,1,n-1){
			E[i].u=read();
			E[i].v=read();
			add(E[i].u,E[i].v);
			add(E[i].v,E[i].u);
			d[E[i].u]++;
			d[E[i].v]++;
		}
		dfs0(0,1);
		fr(i,1,n-1) if(dep[E[i].u]>dep[E[i].v]) swap(E[i].u,E[i].v);
		fr(i,1,k){
			ll x=read();
			ck[E[x].v]=1;
		}
		jc[0]=1;
		fr(i,1,n) jc[i]=jc[i-1]*i%mod;
		jcinv[n]=my_pow(jc[n],mod-2);
		pfr(i,n-1,0) jcinv[i]=jcinv[i+1]*(i+1)%mod;
		fr(i,1,n) invv[i]=jcinv[i]*jc[i-1]%mod;
		fr(i,1,n) fr(j,1,d[i]-1) all=all*j%mod;
		dfs(0,1);
		writeln(all*f[1]%mod);
		clr();
	}
}
