#include<bits/stdc++.h>
#define Yzl unsigned long long
#define fi first
#define se second
#define pi pair<int,int>
#define mp make_pair
#define pb emplace_back
#define lob lower_bound
#define upb upper_bound
typedef long long LL;

using namespace std;

const Yzl Lty=20120712;

const int MAXN=1e5+10,P=1e9+7;
int c,n,k;
int a[MAXN],dep[MAXN],Fa[MAXN];
bool sf[MAXN];
struct ddl {
	int u,v;
}E[MAXN];
vector<int> e[MAXN];
LL pw[MAXN],mul,inv[MAXN],ans;
LL ksm(LL x,LL y=P-2) { LL ret=1;
	while(y) {
		if(y&1) ret=ret*x%P;
		x=x*x%P; y>>=1;
	} return ret;
}
LL fad(LL x,LL y) {
	return (x+y>=P?x+y-P:x+y);
}
void add(int f,int t) {
	e[f].pb(t);
}
void dfs(int u,int fa) {
	dep[u]=dep[fa]+1; mul=mul*pw[e[u].size()-1]%P; Fa[u]=fa;
	for(auto t:e[u]) if(t!=fa) dfs(t,u);
}
LL f[MAXN],cf[MAXN],tot[MAXN],xs[MAXN]; 
void rdfs(int u,int fa) {
	tot[u]=e[u].size()-(fa>0); cf[u]=inv[e[u].size()-1]%P;
	xs[u]=mul; bool pd=0;
	for(auto t:e[u]) if(t!=fa) { pd=1;
		--tot[u];
		if(sf[t]) {
			int x=u; LL as=1;
			while(x) { as=as*cf[x]%P;
				LL cgl=fad(tot[x],f[x])*as%P;
				ans=fad(ans,cgl*xs[u]%P);
				if(sf[x]) break;
				x=Fa[x];
			}
		} 
		rdfs(t,u);
		if(!sf[t]) f[u]=fad(f[u],f[t]); 
	} 
	if(!pd) f[u]=1;
	else f[u]=f[u]*cf[u]%P;
}
void vmain() {
	scanf("%d%d",&n,&k); 
	for(int i=1;i<=n;++i) e[i].clear(),sf[i]=0,f[i]=0;
	for(int i=1;i<n;++i) scanf("%d%d",&E[i].u,&E[i].v),add(E[i].u,E[i].v),add(E[i].v,E[i].u);
	for(int i=1;i<=k;++i) scanf("%d",&a[i]);
	if(c==18) {
		puts("1");
		return ;
	}
	int rt=0;
	for(int i=1;i<=n;++i) if((int)e[i].size()>1) rt=i;
	mul=1; dfs(rt,0); ans=0;
	for(int i=1;i<=k;++i) {
		if(dep[E[a[i]].u]>dep[E[a[i]].v]) swap(E[a[i]].u,E[a[i]].v);
		sf[E[a[i]].v]=1;
	} rdfs(rt,0);
	printf("%lld\n",ans);
}
int main () {
	freopen("traverse.in","r",stdin);
	freopen("traverse.out","w",stdout);
	pw[0]=inv[0]=1; for(int i=1;i<=MAXN-10;++i) pw[i]=pw[i-1]*i%P,inv[i]=ksm(pw[i]);
	for(int i=1;i<=MAXN-10;++i) inv[i]=inv[i]*pw[i-1]%P;
	int T; scanf("%d%d",&c,&T); while(T--) vmain();
	return 0;
}
