#include <bits/stdc++.h>
#define For(e,e1,e2) for(int e=(e1);e<=(e2);e++)
#define For_(e,e1,e2) for(int e=(e1);e<(e2);e++)
#define Rof(e,e1,e2) for(int e=(e2);e>=(e1);e--)
#define Rof_(e,e1,e2) for(int e=(e2);e>(e1);e--)
#define exc(e) if(e) continue
#define stop(e) if(e) break
#define ret(e) if(e) return 
#define LL long long
#define ULL unsigned long long
#define DB double
#define cint const int
#define cLL const long long
#define vct vector
#define pb push_back
#define ft first
#define sc second
using namespace std;
void main_init()
{
	
}
cLL mod=1000000007ll;
LL md(LL w)
{
	w%=mod;
	if(w<0ll) w+=mod;
	return w;
}
int ooo;
cint N=100200;
int n,m;
vct <int> v[N];
vct <int> h;
vct <array<int,2> > ed;
LL d1[N];
int d[N];
vct <int> g[N];
void dfs(int p,int fa)
{
	g[p].pb(fa);
	for(auto i:v[p])
	{
		exc(i==fa);
		dfs(i,p);
	}
}
void work(int x,int y)
{
	dfs(x,y),dfs(y,x);
}
void main_solve()
{
	scanf("%d%d",&n,&m);
	d1[0]=1ll; For(i,1,n) d1[i]=d1[i-1]*i%mod;
	For(i,1,n) v[i].clear();
	ed.clear();
	For_(i,1,n)
	{
		int x,y; scanf("%d%d",&x,&y);
		ed.pb({x,y});
		v[x].pb(y),v[y].pb(x);
	}
	For(i,1,n) d[i]=(int)v[i].size();
	h.resize(m); For_(i,0,m) scanf("%d",&h[i]),h[i]--;
	int p=1<<m;
	LL ans=0ll;
	For_(k,1,p)
	{
		For(i,1,n) g[i].clear();
		For_(i,0,m) if(k>>i&1)
			work(ed[h[i]][0],ed[h[i]][1]);
		LL s=1ll;
		For(i,1,n)
		{
			sort(g[i].begin(),g[i].end());
			g[i].erase(unique(g[i].begin(),g[i].end()),g[i].end());
			int t=(int)g[i].size();
			if(t>2)
			{
				s=0ll;
				break;
			}
			s=s*d1[d[i]-t]%mod; 
		}
		if(__builtin_popcount(k)&1) ans+=s;
		else ans-=s;
	}
	ans=md(ans);
	printf("%lld\n",ans);
}
int main()
{
	freopen("traverse.in","r",stdin);
	freopen("traverse.out","w",stdout);
	main_init();
	int _; scanf("%d%d",&ooo,&_); while(_--) 
		main_solve();
	return 0;
}
/*

*/
