#include<bits/stdc++.h>
#define int long long
#define mod 1000000007ll
#define pii pair<int,int>
#define fi first
#define se second
#define pb push_back
#define mems(a,x) memset(a,x,sizeof(a))
using namespace std;
const int maxn=100010;
const int inf=1e18;
inline int read(){
	int x=0,fl=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')fl=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=(x<<3)+(x<<1)+(ch-'0');ch=getchar();}
	return x*fl;
}
bool mbe;

int op;
int n,k,ans;
int fac[maxn],inv[maxn];
inline int ksm(int a,int b=mod-2){
	int ans=1;
	while(b){
		if(b&1)ans=ans*a%mod;
		a=a*a%mod;
		b>>=1;
	}
	return ans;
}
pii g[maxn];
int head[maxn],tot;
struct nd{
	int nxt,to;
}e[maxn<<1];
void add(int u,int v){e[++tot]={head[u],v};head[u]=tot;}
int a[maxn];
int d[maxn],fa[maxn];
int dfn[maxn],rnk[maxn],idx,siz[maxn];
void dfs(int u){
	rnk[dfn[u]=++idx]=u;siz[u]=1;
	for(int i=head[u];i;i=e[i].nxt){
		int v=e[i].to;if(v==fa[u])continue;
		fa[v]=u;dfs(v);siz[u]+=siz[v];
	}
}
#define lb(x) (x&(-x))
int tree[maxn];
void upd(int x){
	while(x<=n)tree[x]++,x+=lb(x);
}
int que(int x){
	int res=0;
	while(x)res+=tree[x],x-=lb(x);
	return res;
}
int que(int l,int r){
	if(l>r)return 0;
	return que(r)-que(l-1);
}
int vis[maxn];
void work(){
	n=read();k=read();ans=1;
	for(int i=1;i<=n;i++)d[i]=head[i]=0;tot=0;
	for(int i=1;i<n;i++){
		int u=read(),v=read();
		add(u,v),add(v,u);
		d[u]++,d[v]++;
		g[i]={u,v};
	}
	for(int i=1;i<=k;i++)a[i]=read();
	if(k==1){
		for(int i=1;i<=n;i++)ans=ans*fac[d[i]-1]%mod;
		printf("%lld\n",ans);
		return ;
	}
	if(op==18){puts("1");return ;}
	idx=0;dfs(1);
	for(int i=1;i<=k;i++){
		int u=g[a[i]].fi,v=g[a[i]].se;
		if(v==fa[u])swap(u,v);
		upd(dfn[v]);
	}
	for(int i=1;i<=n;i++)ans=ans*fac[d[i]-1]%mod;
	int res=k*ans%mod;
	for(int u=1;u<=n;u++){
		ans=ans*inv[d[u]-1]%mod;
		int num=0;
		for(int i=head[u];i;i=e[i].nxt){
			int v=e[i].to,sz=0;
			if(v==fa[u]){
				sz=que(1,dfn[u])+que(dfn[u]+siz[u],n);
			}
			else{
				sz=que(dfn[v],dfn[v]+siz[v]-1);
			}
			// cout<<u<<" "<<v<<" "<<sz<<"\n";
			(res+=mod-sz*fac[d[u]-2]%mod*num%mod)%=mod;
			if(sz)++num;
		}
		ans=ans*fac[d[u]-1]%mod;
	}
	for(int i=1;i<=n;i++)tree[i]=0;
	printf("%lld\n",res);
}

bool med;
int T;
signed main(){
	freopen("traverse.in","r",stdin);
	freopen("traverse.out","w",stdout);
	
	// cerr<<(&mbe-&med)/1024.0/1024.0<<"\n";
	
	op=read();T=read();
	fac[0]=1;for(int i=1;i<=maxn-10;i++)fac[i]=fac[i-1]*i%mod;
	inv[maxn-10]=ksm(fac[maxn-10]);for(int i=maxn-11;~i;i--)inv[i]=inv[i+1]*(i+1)%mod;
	while(T--)work();
}