#include<bits/stdc++.h>
using namespace std;
#define max_n 200100
#define mod 1000000007ll
long long fac[max_n+2];
long long inv[max_n+2];
long long ew[max_n+2];//生成树个数 
int sid;
int tid;
int n;
int q;
struct E{int u,v;}e[max_n+2];
vector<pair<int,int>>g[max_n+2];
int que[max_n+2];
long long cnte[max_n+2];//这个点连了多少条边
long long cntq[max_n+2];//其中又有多少关键边
int st[max_n+2],top=0;
int posu=0,posv=0;
int fa[max_n+2];
vector<int>son[max_n+2];
int now[max_n+2];
long long dp[max_n+2];
long long ans=0;
inline long long read(){
	long long res=0;
	char c=getchar();
	while(c<'0'||c>'9')c=getchar();
	while(c>='0'&&c<='9'){res=res*10+(c^48); c=getchar();}
	return res;
}
inline long long qp(long long a,long long b){
	long long res=1;
	while(b){
		if(b&1)res=res*a%mod;
		a=a*a%mod; b>>=1;
	}
	return res;
}
inline long long C(long long n,long long m){
	if(n<0||m<0||n<m)return 0;
	return fac[n]*inv[m]%mod*inv[n-m]%mod;
}
inline long long calc(int u,long long x){//钦定好这个集团有x个点度数为1或0，其他不管 
	if(x>cntq[u])return 0;
	if(cnte[u]==1)return 1;
	return ew[cnte[u]-x]*qp(cnte[u]-x,x)%mod; 
}
inline void dfs(int u,int f){
	fa[u]=f; dp[u]=1;
	for(auto v:g[u]){
		if(v.first!=f){
			son[u].push_back(v.first); dfs(v.first,u);
			dp[u]=dp[u]*dp[v.first]%mod;
		}
	}
//	printf("si=%d\n",(int)son[u].size());
	dp[u]=dp[u]*fac[(int)son[u].size()]%mod;
}
inline void dfs2(int x){
	if(x>q){
		if(!top)return;
		posu=e[st[1]].u; posv=e[st[1]].v;
		for(int i=1;i<=n;++i){fa[i]=0; son[i].clear();}
		dfs(posu,posv); dfs(posv,posu);
		long long res=dp[posu]*dp[posv]%mod;
		for(int i=1;i<=n;++i)now[i]=0;
		for(int i=2;i<=top;++i){
			if(e[st[i]].u==fa[e[st[i]].v])++now[e[st[i]].u];
			else ++now[e[st[i]].v];
		}
		for(int i=1;i<=n;++i){
			if(now[i]>=2){res=0; break;}
			if(now[i]==0)continue;
			res=res*inv[(int)son[i].size()]%mod;
		}
		if(top&1)ans=(ans+res)%mod;
		else ans=(ans-res+mod)%mod;
//		printf("top=%d %d %lld %d %d\n",top,st[1],res,son[posu].size(),son[posv].size());
		return;
	}
	dfs2(x+1);
	st[++top]=que[x]; dfs2(x+1); --top;
}
namespace SUBA{
	bool check(){
		int cnt=0;
		for(int i=1;i<=n;++i){
			if(cnte[i]==1)++cnt;
		}
		return cnt<=2;
	}
	void work(){
		printf("%d\n",1);
		return;
	}
}
namespace SUBB{
	bool check(){
		return cnte[1]==n-1;
	}
	void work(){
		printf("%lld\n",(fac[n-1]*inv[2]%mod-C((n-1)-q,2)*fac[n-1-2]%mod+mod)%mod);
	}
}
int main(){
	freopen("traverse.in","r",stdin);
	freopen("traverse.out","w",stdout);
	fac[0]=1;
	for(int i=1;i<=max_n;++i)fac[i]=fac[i-1]*i%mod;
	inv[max_n]=qp(fac[max_n],mod-2);
	for(int i=max_n-1;i>=0;--i)inv[i]=inv[i+1]*(i+1)%mod;
	ew[0]=ew[1]=ew[2]=1;
	for(int i=3;i<=max_n;++i)ew[i]=qp(i,i-2);
	sid=read(); tid=read();
	for(int ca=1;ca<=tid;++ca){
		n=read(); q=read();
		for(int i=1;i<n;++i){e[i].u=read(); e[i].v=read();}
		for(int i=1;i<=n;++i)g[i].clear();
		for(int i=1;i<n;++i){g[e[i].u].push_back({e[i].v,i}); g[e[i].v].push_back({e[i].u,i});}
		for(int i=1;i<=q;++i)que[i]=read();
		for(int i=1;i<=n;++i)cnte[i]=cntq[i]=0;
		for(int i=1;i<n;++i){++cnte[e[i].u]; ++cnte[e[i].v];}
		for(int i=1;i<=q;++i){++cntq[e[que[i]].u]; ++cntq[e[que[i]].v];}
		if(SUBA::check()){SUBA::work(); continue;}
		if(SUBB::check()){SUBB::work(); continue;}
		ans=0;
//		for(int i=1;i<=n;++i)printf("%d ",cnte[i]); printf("\n");
		dfs2(1);
		printf("%lld\n",ans);
	}
	return 0;
}

