#include<bits/stdc++.h>
#define LL long long
#define db double
#define pii pair<int,int>
#define fi first
#define se second
using namespace std;

const int N=1e5+10,MOD=1e9+7;

int n,K,q[N];
int fac[N],ifac[N];
vector <int> g[N];
struct Edge{int x,y;}e[N];

void addm(int &x,int y){(x+=y<0? MOD+y:y)%=MOD;}

int ksm(int x,int y)
{
	int res=1;
	while(y)
	{
		if(y&1) res=1LL*res*x%MOD;
		x=1LL*x*x%MOD; y>>=1;
	}
	return res;
}

void init(int n)
{
	fac[0]=ifac[0]=1;
	for(int i=1; i<=n; i++)
		fac[i]=1LL*fac[i-1]*i%MOD;
	ifac[n]=ksm(fac[n],MOD-2);
	for(int i=n-1; i>=1; i--)
		ifac[i]=1LL*ifac[i+1]*(i+1)%MOD;
}

namespace Sub1
{
	int ans;
	
	void dfs(int x,int fa)
	{
		int t=g[x].size()-1;
		ans=1LL*ans*fac[t]%MOD;
		for(int y:g[x])
			if(y!=fa) dfs(y,x);
	}
	
	void solve()
	{
		int x=e[q[1]].x,y=e[q[1]].y;
		ans=1;
		dfs(x,y); dfs(y,x);
		cout<<ans<<"\n";
	}
}

namespace Sub2
{
	int ans;
	
	void dfs(int x,int fa,int u,int v)
	{
		int t=g[x].size()-1,res=fac[t];
		for(int y:g[x])
		{
			if(y==fa) continue;
			dfs(y,x,u,v);
			if((x==u && y==v) || (x==v && y==u))
				addm(res,fac[t]), addm(res,-fac[t-1]);
		}
//		cout<<x<<" "<<res<<" "<<fac[t]<<" "<<t<<"\n";
		ans=1LL*ans*res%MOD;
	}
	
	void solve()
	{
		int x=e[q[1]].x,y=e[q[1]].y;
		int u=e[q[2]].x,v=e[q[2]].y;
		ans=1;
		dfs(x,y,u,v); dfs(y,x,u,v);
		cout<<ans<<"\n";
	}
}

void mian(int type)
{
	cin>>n>>K;
	
	for(int i=1; i<=n; i++)
		g[i].clear();
		
	for(int i=1; i<n; i++)
	{
		cin>>e[i].x>>e[i].y;
		g[e[i].x].push_back(e[i].y);
		g[e[i].y].push_back(e[i].x);
	}
	
	for(int i=1; i<=K; i++)
		cin>>q[i];
		
	if(type<=6) Sub1::solve(); 
	else if(type<=10) Sub2::solve();
}

int main()
{
	freopen("traverse.in","r",stdin);
	freopen("traverse.out","w",stdout);
	
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	
	init(N-10);

	int type,T; cin>>type>>T;
	while(T--) mian(type);

	return 0;
}

