#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
namespace solve{
	inline ll read(){
		ll tmp=1,f=0;
		char a=getchar();
		while(a<'0' or a>'9')tmp=a=='-'?-1:tmp,a=getchar();
		while(a>='0' and a<='9')f=(f<<3)+(f<<1)+(a^48),a=getchar();
		return tmp*f;
	}
	inline void write(ll x){
		if(x<0)putchar('-'),x=-x;
		if(x>9)write(x/10);
		putchar(x%10+'0');
	}
	const int N=1e5+5,V=2e6+5,mod=1e9+7;
	int n,m,siz[N],son[N],dep[N],fa[N],prime[N],fac[N],cnt,id=1,f[N],in[N],ans;
	ull g[N],c=17,a[N<<1];
	bool flag[V];
	int H[N<<1],head[N],nxt[N<<1],to[N<<1];
	inline ull shift(ull x){
		x^=(x<<13);
		x^=(x>>7);
		x^=(x>>5);
		return x;
	}
	inline void add(int u,int v,ull w){nxt[++id]=head[u];H[id]=u,to[id]=v;head[u]=id,a[id]=w;}
	inline void dfs(int u,int ff){
		siz[u]=f[1]=1,g[u]=c,dep[u]=dep[fa[u]=ff]+1;
		for(int i=head[u];i;i=nxt[i]){
			int v=to[i];
			if(v==ff)continue;
			son[u]++,dfs(v,u),siz[u]+=siz[v];
			g[u]+=g[v]*prime[siz[v]];
		}
	}
	inline void build(int p){
		
	}
	void main(){
		freopen("traverse.in","r",stdin);
		freopen("traverse.out","w",stdout);
		fac[0]=1;
		for(int i=1;i<N;i++)fac[i]=fac[i-1]*1ll*i%mod;
		for(int i=2;i<V;i++){
			if(flag[i])continue;
			prime[++cnt]=i;
			for(int j=i;1ll*j*i<V;j++)
				flag[j*i]=1;
		}
		for(int c=read(),T=read();T;T--){
			n=read(),m=read(),ans=0;
			std::memset(head,0,sizeof(head)),id=1;
			std::memset(in,0,sizeof(in));
			for(int i=1;i<=n-1;i++){
				int u=read(),v=read();ull col=shift(11);
				add(u,v,col),add(v,u,col);
				in[u]++,in[v]++;
			}
			dfs(1,0);
			int tmpa=0,tmpb=0;
			for(int i=1;i<=n;i++)tmpa+=in[i]==1;
			while(m--){
				int k=read();
				if(tmpa==n-1){
					ans=(ans+fac[n-2])%mod;
				}else if(tmpa==2){
					int u=H[k<<1],v=to[k<<1];
					if(dep[u]<dep[v])std::swap(u,v);
					ans=(ans+1ll*(siz[u]-1)*(n-siz[u]-1)%mod)%mod;
				}
			}
			write(ans),putchar('\n');
		}
		return;
	}
}
int main(){
	solve::main();
	return 0;
}
/*

*/
