#include<cstdio>
#include<algorithm>
using namespace std;
inline long long read()
{
	long long x(0),f(1); char ch(getchar());
	while(ch<'0'||ch>'9'){
		if(ch=='-') f=-1; ch=getchar();
	} while(ch>='0'&&ch<='9')
		x=(x<<1)+(x<<3)+(ch^48),ch=getchar();
	return x*f;
} const long long M(1e9+7);
struct acg{long long x,y;}a[100005];
long long T,S,n,m,s,c,q[100005],d[100005],v[100005],h[100005],p[200005],t[200005];
void add(int x,int y){t[++c]=y; p[c]=h[x]; h[x]=c; return;}
void cl(long long x){long long y(0),z(0); v[x]=1;
	for(long long i=h[x];i;i=p[i]){
		y++; if(v[t[i]]||d[i/2]) z++;
		if(!v[t[i]]) cl(t[i]);
	} if(y>1) s=q[y-2]*(y-z)%M*s%M;
	//printf("%lld %lld %lld %lld\n",x,s,y,z);
	return;
}
int main()
{
	freopen("traverse.in","r",stdin); freopen("traverse.out","w",stdout);
	T=read(); T=read(); q[0]=1;
	for(long long i=1;i<=1e5;i++) q[i]=q[i-1]*i%M;
	while(T--){
		int x,y; n=read(); m=read(); S=0; c=1;
		for(int i=1;i<n;i++){
			a[i].x=x=read(); a[i].y=y=read();
			add(x,y); add(y,x);
		} for(int i=1;i<=m;i++){
			for(int j=1;j<=n;j++) v[j]=0;
			x=read(); d[x]=s=1;
			v[a[x].x]=v[a[x].y]=1;
			cl(a[x].x); cl(a[x].y);
			S=(S+s)%M;
			//printf("%lld %lld aaa\n",S,s);
		} printf("%lld\n",S);
		for(int i=1;i<=n;i++) h[i]=d[i]=a[i].x=a[i].y=0;
	} return 0;
}
