#include<bits/stdc++.h>
#define ll long long
#define mp(a,b) make_pair(a,b)
using namespace std;
const ll MAXN=1e5+5,MOD=1e9+7;
ll c,T,n,k,e[MAXN],cnt[MAXN],num[MAXN],fact[MAXN];
vector<pair<ll,ll> > G[MAXN];
pair<ll,ll> edge[MAXN];
bool used[MAXN];
inline int read()
{
	int s=0;
	char c=getchar();
	while(c<'0'||c>'9') c=getchar();
	while(c>='0'&&c<='9')
	{
		s=s*10+(c-'0');
		c=getchar();
	}
	return s;
}
ll Pow(ll a,ll x)
{
	ll s=1;
	while(x)
	{
		if(x%2) s=s*a%MOD;
		x/=2;
		a=a*a%MOD;
	}
	return s;
}
void subtask1()
{
	ll all=1;
	for(ll i=1;i<=n;i++)
		all=fact[G[i].size()-1]*all%MOD;
	printf("%lld\n",all);
}
class Subtask2
{
	private:
		bool vis[MAXN];
	public:
		bool dfs(ll d,ll fa,ll x)
		{
			for(ll i=0;i<G[d].size();i++)
				if(G[d][i].first!=fa&&(G[d][i].second==x||dfs(G[d][i].first,d,x)))
				{
					vis[d]=true;
					return true;
				}
			return false;
		}
		void work()
		{
			memset(vis,0,sizeof(vis));
			dfs(edge[e[1]].first,edge[e[1]].second,e[2]);
			dfs(edge[e[1]].second,edge[e[1]].first,e[2]);
			ll all=1,remove=1;
			for(ll i=1;i<=n;i++)
			{
				all=fact[G[i].size()-1]*all%MOD;
				if(vis[i]) remove=fact[G[i].size()-2]%MOD*remove%MOD;
				else remove=fact[G[i].size()-1]*remove%MOD;
			}
			printf("%lld\n",(all*2%MOD-remove+MOD)%MOD);
		}
}subtask2;
int main()
{
	freopen("traverse.in","r",stdin);
	freopen("traverse.out","w",stdout);
	fact[0]=1;
	for(ll i=1;i<=100000;i++)
		fact[i]=fact[i-1]*i%MOD;
	c=read(),T=read();
	while(T--)
	{
		n=read(),k=read();
		for(ll i=1;i<=n;i++) G[i].clear();
		for(ll i=1;i<n;i++)
		{
			edge[i].first=read(),edge[i].second=read();
			G[edge[i].first].push_back(mp(edge[i].second,i));
			G[edge[i].second].push_back(mp(edge[i].first,i));
		}
		for(ll i=1;i<=k;i++) e[i]=read();
		if(k==1) subtask1();
		else if(k==2) subtask2.work();
	}
	return 0;
}
