#include<cstdio>
using namespace std;
namespace IO
{
	const int lim=1000000;
	int curin,topin,topout;
	char in[lim+100],out[lim+100];
	char get()
	{
		if(curin==topin)
		{
			curin=0;
			topin=fread(in,1,lim,stdin);
		}
		if(topin==0)
		return 0;
		return in[curin++];
	}
	void read(long long &x,int l=100)
	{
		int len=1;
		char c=get();
		while(c<'0'||c>'9')
		c=get();
		x=c-'0';
		while(len<l)
		{
			c=get();
			if(c<'0'||c>'9')
			return;
			x=x*10+c-'0';
		}
	}
	void flush()
	{
		fwrite(out,1,topout,stdout);
		topout=0;
	}
	class _{public:~_(){flush();}}__;
	void put(char c)
	{
		if(topout==lim)
		flush();
		out[topout++]=c;
	}
	void print(long long x)
	{
		if(x<10)
		put(x+'0');
		else
		{
			print(x/10);
			put(x%10+'0');
		}
	}
}
using IO::put;
using IO::read;
using IO::print;
const long long mod=1000000007;
long long Cid,T,I,i,j,n,k,pans,ans,sum,e[110000],fl[110000],fac[110000],zl[110000],ll[110000],rr[110000],topr;
long long u[110000],v[110000],num[110000],*mp[110000],deep[110000],fa[110000];
long long tree[410000],tag[410000],t[1100000],l[1100000],r[1100000],val[1100000],qnum[1100000],q[1100000],ny[110000],top;
long long power(long long a,long long b)
{
	long long k=a,ans=1;
	while(b)
	{
		if(b&1)
		ans=ans*k%mod;
		k=k*k%mod;
		b=b>>1;
	}
	return ans;
}
void dfs1(long long x,long long d)
{
	long long i;
	deep[x]=d;
	for(i=1;i<=mp[x][0];i++)
	if(mp[x][i]!=fa[x])
	{
		fa[mp[x][i]]=x;
		dfs1(mp[x][i],d+1);
	}
}
void dfs2(long long x)
{
	long long i;
	ll[x]=topr+1;
	topr=topr+fl[x];
	zl[x]=topr+1;
	for(i=1;i<=mp[x][0];i++)
	if(mp[x][i]!=fa[x])
	dfs2(mp[x][i]);
	rr[x]=topr;
}
void sort(long long l,long long r)
{
	long long mid=(l+r)/2,i=l,j=mid+1,k=l;
	if(l==r)
	{
		q[l]=qnum[l];
		return;
	}
	sort(l,mid);
	sort(mid+1,r);
	while(i<=mid&&j<=r)
	{
		if(t[q[i]]<=t[q[j]])
		{
			qnum[k]=q[i];
			i++;
		}
		else
		{
			qnum[k]=q[j];
			j++;
		}
		k++;
	}
	while(i<=mid)
	{
		qnum[k]=q[i];
		i++;
		k++;
	}
	while(j<=r)
	{
		qnum[k]=q[j];
		j++;
		k++;
	}
	for(i=l;i<=r;i++)
	q[i]=qnum[i];
}
void down(long long l,long long r,long long m)
{
	if(tag[m]!=1&&l<r)
	{
		tag[m*2]=tag[m*2]*tag[m]%mod;
		tree[m*2]=tree[m*2]*tag[m]%mod;
		tag[m*2+1]=tag[m*2+1]*tag[m]%mod;
		tree[m*2+1]=tree[m*2+1]*tag[m]%mod;
	}
	tag[m]=1;
}
void build(long long l,long long r,long long m)
{
	long long mid=(l+r)/2;
	tree[m]=r-l+1;
	tag[m]=1;
	if(l==r)
	return;
	build(l,mid,m*2);
	build(mid+1,r,m*2+1);
}
void in(long long ll,long long rr,long long v,long long l=1,long long r=k,long long m=1)
{
	long long mid=(l+r)/2;
	if(l>rr||r<ll)
	return;
	if(l>=ll&&r<=rr)
	{
		tree[m]=tree[m]*v%mod;
		tag[m]=tag[m]*v%mod;
		return;
	}
	down(l,r,m);
	in(ll,rr,v,l,mid,m*2);
	in(ll,rr,v,mid+1,r,m*2+1);
	tree[m]=(tree[m*2]+tree[m*2+1])%mod;
}
long long get(long long ll,long long rr,long long l=1,long long r=k,long long m=1)
{
	long long mid=(l+r)/2;
	if(l>rr||r<ll)
	return 0;
	if(l>=ll&&r<=rr)
	return tree[m];
	down(l,r,m);
	return (get(ll,rr,l,mid,m*2)+get(ll,rr,mid+1,r,m*2+1))%mod;
}
int main()
{
	freopen("traverse.in","r",stdin);
	freopen("traverse.out","w",stdout);
	read(Cid);
	read(T);
	if(Cid==18)
	{
		for(I=1;I<=T;I++)
		{
			print(1);
			put('\n');
		}
		return 0;
	}
	fac[0]=1;
	for(i=1;i<=100000;i++)
	fac[i]=fac[i-1]*i%mod;
	for(i=1;i<=100000;i++)
	ny[i]=power(i,mod-2);
	for(I=1;I<=T;I++)
	{
		read(n);
		read(k);
		for(i=1;i<n;i++)
		{
			read(u[i]);
			read(v[i]);
			num[u[i]]++;
			num[v[i]]++;
		}
		for(i=1;i<=k;i++)
		read(e[i]);
		for(i=1;i<=n;i++)
		{
			mp[i]=new long long[num[i]+1];
			mp[i][0]=0;
		}
		for(i=1;i<n;i++)
		{
			mp[u[i]][0]++;
			mp[u[i]][mp[u[i]][0]]=v[i];
			mp[v[i]][0]++;
			mp[v[i]][mp[v[i]][0]]=u[i];
		}
		dfs1(1,1);
		for(i=1;i<=k;i++)
		if(deep[u[e[i]]]<deep[v[e[i]]])
		fl[v[e[i]]]++;
		else
		fl[u[e[i]]]++;
		topr=0;
		dfs2(1);
		pans=1;
		for(i=1;i<=n;i++)
		pans=pans*fac[num[i]-1]%mod;
		sum=k;
		top=0;
		for(i=1;i<=n;i++)
		if(num[i]>1)
		{
			for(j=1;j<=mp[i][0];j++)
			if(mp[i][j]!=fa[i])
			{
				top++;
				t[top]=ll[mp[i][j]];
				l[top]=rr[mp[i][j]]+1;
				r[top]=k;
				val[top]=ny[num[i]-1];
				top++;
				t[top]=rr[mp[i][j]]+1;
				l[top]=rr[mp[i][j]]+1;
				r[top]=k;
				val[top]=num[i]-1;
			}
			top++;
			t[top]=1;
			l[top]=zl[i];
			r[top]=rr[i];
			val[top]=ny[num[i]-1];
			top++;
			t[top]=zl[i];
			l[top]=zl[i];
			r[top]=rr[i];
			val[top]=num[i]-1;
			top++;
			t[top]=rr[i]+1;
			l[top]=zl[i];
			r[top]=rr[i];
			val[top]=ny[num[i]-1];
		}
		for(i=1;i<=top;i++)
		qnum[i]=i;
		sort(1,top);
		build(1,k,1);
		j=1;
		for(i=1;i<k;i++)
		{
			while(j<=top&&t[qnum[j]]<=i)
			{
				if(l[qnum[j]]<=r[qnum[j]]&&r[qnum[j]]>i)
				in(l[qnum[j]],r[qnum[j]],val[qnum[j]]);
				j++;
			}
			sum=(sum-get(i+1,k)+mod)%mod;
		}
		ans=pans*sum%mod;
		print(ans);
		put('\n');
		for(i=1;i<=n;i++)
		{
			num[i]=0;
			fl[i]=0;
			delete [] mp[i];
		}
	}
	return 0;
}
