#include<bits/stdc++.h>
#define ri register int
#define ll long long
#define rll register ll
#define ull unsigned ll
#define fo(i,x,y) for(ri i=(x);i<=(y);++i)
#define fu(i,x,y) for(ri i=(x);i<(y);++i)
#define fd(i,x,y) for(ri i=(x);i>=(y);--i)
#define pb push_back
#define pii pair<int,int>
#define fi first
#define se second
using namespace std;
const int N=1e5+5,p=1e9+7;
int T,n,k,du[N],jc[N],ny[N],ans,a[N];
int dep[N];
struct nd{int x,y;}e[N];
vector<int>G[N];
inline int read(){
	ri p=0;
	register char ch=getchar();
	while(ch<'0'||ch>'9')ch=getchar();
	while(ch>='0'&&ch<='9'){
		p=p*10+ch-48;
		ch=getchar();
	}
	return p;
}
inline int ksm(ri x,ri y){
	ri sm=1;
	if(y<0)return 1;
	for(;y;y>>=1,x=1ll*x*x%p)
	if(y&1)sm=1ll*sm*x%p;
	return sm;
}
inline void dfs(ri x,ri fa){
	dep[x]=dep[fa]+1;
	for(auto y:G[x])if(y!=fa)dfs(y,x);
}
int main(){
	freopen("traverse.in","r",stdin);
	freopen("traverse.out","w",stdout);
	scanf("%d%d",&T,&T);
	jc[0]=ny[0]=1;
	fo(i,1,1e5){
		jc[i]=1ll*jc[i-1]*i%p;
		ny[i]=ksm(i,p-2);
	}
	while(T--){
		scanf("%d%d",&n,&k);
		fo(i,1,n)G[i].clear(),du[i]=0;
		fo(i,1,n-1){
			ri x=read(),y=read();
			e[i]=(nd){x,y};
			G[x].pb(y);G[y].pb(x);
			++du[x];++du[y];
		}
		dfs(1,0);
		fo(i,1,k)a[i]=read();
		fo(i,1,n-1){
			if(e[i].x>e[i].y)swap(e[i].x,e[i].y);
		}
		sort(a+1,a+1+k,[&](ri x,ri y){return dep[e[x].x]>dep[e[y].x];});
		ans=0;ri s=1;
		fo(i,1,n){
			if(du[i]==1)continue;
			s=1ll*s*jc[du[i]-1]%p;
		}
		fo(i,1,k){
			if(!s)break;
			(ans+=s)%=p;
			ri x=e[a[i]].x;
			s=1ll*s*ny[du[x]-1]%p;
			--du[x];
			s=1ll*s*(du[x]-1)%p;
		}
		printf("%d\n",ans);
	}
}
