#include<algorithm>
#include<stdio.h>
#define ll long long
#define N 100005
using namespace std;
ll read() {
	char c=getchar(); ll x=0;
	while(!(c >= '0' && c <= '9')) c=getchar();
	while(c >= '0' && c <= '9') x=x*10+c-'0', c=getchar();
	return x;
}
int cc, T;
int n, k;
int head[N], to[N<<1], nex[N<<1], m1;
void add(int u, int v) {to[++m1]=v, nex[m1]=head[u], head[u]=m1;}
const ll mod=1e9+7;
ll f[N], g[N], in[N];
ll jc[N], iv[N];
ll fp(ll x, ll y) {
	ll ans=1;
	for(; y; y>>=1) {
		if(y&1) ans=ans*x%mod;
		x=x*x%mod;
	}
	return ans;
}
void pre() {
	int i;
	jc[0]=1; for(i=1; i<N; i++) jc[i]=jc[i-1]*i%mod;
	iv[N-1]=fp(jc[N-1], mod-2); for(i=N-2; i>=0; i--) iv[i]=iv[i+1]*(i+1)%mod;
}

ll answer[N];
struct edge {
	int u, v, o;
} E[N];

ll f1[N];
void dfs1(int now, int last) {
	f1[now]=1;
	for(int i=head[now]; i; i=nex[i]) {
		int st=to[i]; if(st == last) continue;
		dfs1(st, now);
		f1[now]=f1[now]*f1[st]%mod*jc[in[st]-1]%mod;
	}
//	printf("%d %lld\n", now, f1[now]);
} 

void update(int now) {
	f1[now]=1;
	for(int i=head[now]; i; i=nex[i]) {
		int st=to[i];
		f1[now]=f1[now]*f1[st]%mod*jc[in[st]-1]%mod;
	}	
}

ll ans;
void dfs2(int now, int last) {
//	ll sum=0, num=0, num1=0;
//	for(int i=head[now]; i; i=nex[i]) {
//		int st=to[i];
//		num1++;
//		if(E[(i+1)/2].o) num++;
//	}
////	printf("%d %d\n", now, num);
//	sum=num*(num-1)/2%mod*jc[num1-2]%mod*f1[now]%mod;
//	ans=(ans-sum+mod)%mod;
	
	for(int i=head[now]; i; i=nex[i]) {
		int st=to[i]; if(st == last) continue;
		ll num=f1[now];
		f1[now]=f1[now]*fp(f1[st], mod-2)%mod*fp(jc[in[st]-1], mod-2)%mod;
//		printf("%d %lld %lld\n", i/2, f1[now], f1[st]);
		answer[(i+1)/2]=f1[now]*jc[in[now]-1]%mod*f1[st]%mod*jc[in[st]-1]%mod;
		update(st);
		dfs2(st, now);
		f1[now]=num;
	}
}

int lis[N], n1;
int main() {
	freopen("traverse.in", "r", stdin);
	freopen("traverse.out", "w", stdout);
	cc=read(), T=read();
	int i;
	pre();
	while(T--) {
		n=read(), k=read();
		bool t1=true, t2=true;
		for(i=1; i<=n; i++) head[i]=0, in[i]=0; m1=0;
		for(i=1; i<n; i++) {
			int u=read(), v=read();
			add(u, v), add(v, u);
			if(v != u+1) t1=false;
			if(u != 1) t2=false;
			E[i]={u, v, 0};
			in[u]++, in[v]++;
		}
		
		ans=0, n1=0;
		for(i=1; i<=k; i++) {
			int x=read(); lis[++n1]=x;
			E[x].o=1;
		}
		dfs1(1, 0), dfs2(1, 0);	
		for(i=1; i<=k; i++) {
			ans=(ans+answer[lis[i]])%mod;
		}
			
		if(t1) {printf("1\n"); continue;}
		if(t2) {
			ll num=jc[n-3]*k%mod*(n-1-k)%mod+1ll*(k)*(k-1)/2%mod*jc[n-3]%mod;
			printf("%lld\n", num%mod); continue;
		}
		printf("%lld\n", ans);
	}
	return 0;
}

