#include<bits/stdc++.h>
using namespace std;typedef long long ll;
int read(){int x=0,f=1;char ch;for(;!isdigit(ch=getchar());)if(ch=='-')f=-1;for(;isdigit(ch);ch=getchar())x=x*10+(ch-'0');return x*f;}
namespace Main
{
	const int N=200010,mod=1e9+7;int ksm(int x,int y=mod-2){int res=1;for(;y;y>>=1,x=1ll*x*x%mod)if(y&1)res=1ll*res*x%mod;return res;}
	int n,m,q,k,ans,f[N],g[N],h[N],fa[N],head[N],d[N],fac[N],to[N<<1],nxt[N<<1],tot,x,y,z,xx,yy,zz,res,suf[N];bool fl[N],vis[N];vector<int>c;void link(int x,int y){to[++tot]=y,++d[y],nxt[tot]=head[x],head[x]=tot;}void init(){for(int i=fac[0]=1;i<N;++i)fac[i]=1ll*fac[i-1]*i%mod;}
	namespace ust{int fa[N],sz[N];int find(int x){return fa[x]==x?x:fa[x]=find(fa[x]);}void merge(int x,int y){y=find(y),fa[x=find(x)]=y,sz[y]+=sz[x];}void init(){for(int i=1;i<m;++i)fa[i]=i,sz[i]=(d[i]==1);}bool Q(int x){return sz[find(x)]>1;}}
	void dfs0(int x){for(int i=head[x];i;i=nxt[i])if(to[i]!=fa[x])fa[to[i]]=x,dfs0(to[i]);if(x<=n){f[fa[x]]=fac[d[x]-1];for(int i=head[x];i;i=nxt[i])if(to[i]!=fa[x])f[fa[x]]=1ll*f[fa[x]]*f[to[i]]%mod;}}
	struct cal{int s,cnt;void clr(){s=1,cnt=0;}void ins(int x){if(x)s=1ll*s*x%mod;else ++cnt;}int qry(int x){if(cnt>(!x))return 0;return x?(1ll*s*ksm(x)%mod):s;}}A;
	void dfs1(int x){if(x<=n){A.clr(),A.ins(fac[d[x]-1]);if(fa[x])A.ins(g[fa[x]]);for(int i=head[x];i;i=nxt[i])if(to[i]!=fa[x])A.ins(f[to[i]]);for(int i=head[x];i;i=nxt[i])if(to[i]!=fa[x])g[to[i]]=A.qry(f[to[i]]);}for(int i=head[x];i;i=nxt[i])if(to[i]!=fa[x])dfs1(to[i]);}
	int calc(){int res=0;for(int i=n+1;i<m;++i)res=(res+1ll*f[i]*g[i])%mod;for(int i=1;i<=n;++i)if(d[i]>1){z=1ll*(fa[i]?g[fa[i]]:1)*fac[d[i]-2]%mod;for(int j=head[i];j;j=nxt[j])if(to[j]!=fa[i])z=1ll*z*f[to[j]]%mod;res=(res-(d[i]-1ll)*d[i]/2%mod*z)%mod;}res=(res+mod)%mod;return res;}
//	pair<int,int>div(int l,int r){if(l==r)return make_pair(f[c[l]],h[c[l]]);int mid=(l+r)>>1;pair<int,int>xx=div(l,mid),yy=div(mid+1,r);return make_pair(1ll*xx.first*yy.first%mod,(1ll*xx.first*yy.second+1ll*xx.second*yy.first)%mod);}
	void dfs2(int x){vis[x]=1;for(int i=head[x];i;i=nxt[i])if(to[i]!=fa[x]&&(to[i]<=n||fl[to[i]]))dfs2(to[i]);
	if(x<=n){if(d[x]==1&&fl[fa[x]])return h[fa[x]]=1,void();c.clear(),zz=1;for(int i=head[x];i;i=nxt[i])if(to[i]!=fa[x]){if(fl[to[i]])c.emplace_back(to[i]);else zz=1ll*zz*f[to[i]]%mod;}q=(int)c.size();
//	for(auto i:c)cout<<f[i]<<' ';cout<<endl;for(auto i:c)cout<<h[i]<<' ';cout<<endl;
	int res=0,s=1,z=0;suf[q]=1;for(int i=q;i--;)suf[i]=1ll*suf[i+1]*f[c[i]]%mod;for(int i=0;i<q;++i)res=(res+1ll*h[c[i]]*suf[i+1]%mod*z)%mod,z=(1ll*z*f[c[i]]+1ll*s*h[c[i]])%mod,s=1ll*s*f[c[i]]%mod;
	z=1ll*z*zz%mod,res=1ll*res*zz%mod;if(d[x]>1)z=1ll*z*fac[d[x]-2]%mod,res=1ll*res*fac[d[x]-2]%mod;if(fa[x])h[fa[x]]=z;
	if(d[x]==1)res+=z;ans=(ans-1ll*(fa[x]?g[fa[x]]:1)*res)%mod;}}
	void cal(int x){for(;fl[fa[x]];x=fa[fa[x]]);dfs2(x);}
	void main()
	{
		cin>>n>>k,m=n*2,memset(fl,1,m+1),memset(vis,0,m+1),memset(d,0,(m+1)<<2),memset(head,0,(m+1)<<2),memset(f,0,(m+1)<<2),memset(g,0,(m+1)<<2),tot=0;for(int i=n+1;i<m;++i)cin>>x>>y,link(x,i),link(i,x),link(y,i),link(i,y);dfs0(1),dfs1(1);
		/*for(int i=n+1;i<m;++i)cout<<f[i]<<" \n"[i==m-1];for(int i=n+1;i<m;++i)cout<<g[i]<<" \n"[i==m-1];*/
		ans=calc(),ust::init();for(;k--;)cin>>x,fl[x+n]=0;fl[0]=0,memset(h,0,(m+1)<<2);for(int i=n+1;i<m;++i)if(fl[i])for(int j=head[i];j;j=nxt[j])ust::merge(to[j],i);
		for(int i=1;i<=n;++i)if(!vis[i]&&ust::Q(i))cal(i);cout<<(ans+mod)%mod<<endl;
	}
}
int main()
{
	freopen("traverse.in","r",stdin);
	freopen("traverse.out","w",stdout);
	int T,c;ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);for(cin>>c>>T,Main::init();T--;)Main::main();
	return 0;
}
