#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<queue>
#include<ctime>
#include<cmath>
#include<set>
#include<map>
#define infile(filename) freopen(filename".in","r",stdin)
#define outfile(filename) freopen(filename".out","w",stdout)
#define usefile(filename) infile(filename),outfile(filename)
using namespace std; typedef long long ll; typedef unsigned long long ull;
char gc() { static const int BUF=1<<20; static char ch[BUF],*l=ch,*r=ch; return (l==r&&(r=(l=ch)+fread(ch,1,BUF,stdin),l==r))?EOF:*l++; }
template <typename T> void read(T &a) { static char ch,fushu; fushu=a=0; do ch=gc(); while(ch!='-'&&(ch<48||ch>57)); if(ch=='-') fushu=1,ch=gc(); do a=(a<<1)+(a<<3)+(ch^48),ch=gc(); while(ch>47&&ch<58); if(fushu) a=-a; return ; }
template <typename T,typename ...Args> void read(T &a,Args &...args) { read(a),read(args...); }
const int N=100099,moder=1000000007,LogN=21;
int add(int x,int y) { return x+y>=moder?x+y>=moder:x+y; } int Add(int &x,int y) { return x=x+y>=moder?x+y-moder:x+y; }
int sub(int x,int y) { return x<y?x-y+moder:x-y; } int Sub(int &x,int y) { return x=x<y?x-y+moder:x-y; }
int kuai(int a,int b) { ll rey=1,temp=a; for(;b;b>>=1) { if(b&1) rey=rey*temp%moder; temp=temp*temp%moder; } return rey; }
int type,T,n,K,fact[N]={},finv[N]={};
namespace taskA {
	void solve() {
		for(int i=1;i<=T;++i)
			printf("1\n");
		return ;
	}
}
namespace taskB {
	void solve() {
		int i,ans,x,y;
		loopB : --T;
		read(n,K);
		for(i=1;i<n;++i)
			read(x,y);
		for(i=1;i<=K;++i)
			read(x);
		printf("%d\n",sub((ll)fact[n-2]*K%moder,n==2?0:(ll)K*(K-1)/2%moder*fact[n-3]%moder));
		if(T) goto loopB;
	}
}
int em=1,e[N*2]={},ls[N]={},nx[N*2]={},cnt[N]={},du[N]={},p[N]={}; pair<int,int> edge[N]={}; bool is[N]={};
int dfn[N]={},tdfn,deep[N]={},fa[N]={},minn[N][LogN]={},val[N]={},invval[N]={},oval[N]={},oinvval[N]={};
void insert(int x,int y) { e[++em]=y,nx[em]=ls[x],ls[x]=em; e[++em]=x,nx[em]=ls[y],ls[y]=em; ++du[x],++du[y]; }
int depmin(int x,int y) { return deep[x]<deep[y]?x:y; }
void dfs(int x) {
	int i,y; minn[dfn[x]=++tdfn][0]=x;
	if(du[x]>1) val[x]=(ll)val[x]*fact[du[x]-2]%moder,
		invval[x]=(ll)invval[x]*finv[du[x]-2]%moder;
	oval[x]=(ll)oval[x]*fact[du[x]-1]%moder;
	oinvval[x]=(ll)oinvval[x]*finv[du[x]-1]%moder;
	for(i=ls[x];y=e[i],i;i=nx[i])
		if(y!=fa[x]) {
			fa[y]=x,deep[y]=deep[x]+1,cnt[y]=cnt[x]+is[i>>1];
			val[y]=val[x],invval[y]=invval[x];
			oval[y]=oval[x],oinvval[y]=oinvval[x];
			dfs(y);
		}
	return ;
}
int lca(int x,int y) {
	if(x==y) return x;
	if(dfn[x]>dfn[y]) swap(x,y);
	int k=__lg(dfn[y]-dfn[x]);
	return fa[depmin(minn[dfn[x]+1][k],minn[dfn[y]-(1<<k)+1][k])];
}
int main()
{
	usefile("traverse");
	int i,j,x,y,z,ans,all;
	read(type,T);
	fact[0]=finv[0]=1;
	for(i=1;i<N;++i) fact[i]=(ll)fact[i-1]*i%moder;
	finv[N-1]=kuai(fact[N-1],moder-2);
	for(i=N-2;i;--i) finv[i]=(ll)finv[i+1]*(i+1)%moder;
	if(type==18) { taskA::solve(); return 0; }
	if(19<=type&&type<=21) { taskB::solve(); return 0; }
	loop : --T;
	read(n,K);
	em=1,memset(ls,0,(n+5)<<2);
	memset(is,false,(n+5));
	memset(du,0,(n+5)<<2);
	for(i=1;i<n;++i)
		read(x,y),insert(x,y),
		edge[i]=make_pair(x,y);
	for(i=1;i<=K;++i)
		read(p[i]),is[p[i]]=true;
	val[0]=invval[0]=val[1]=invval[1]=1;
	oval[0]=oinvval[0]=oval[1]=oinvval[1]=1;
	tdfn=deep[1]=fa[1]=cnt[1]=0,dfs(1);
	for(j=1;(1<<j)<=n;++j)
		for(i=1;i+(1<<j)-1<=n;++i)
			minn[i][j]=depmin(minn[i][j-1],minn[i+(1<<j-1)][j-1]);
	for(i=1;i<n;++i) if(deep[edge[i].first]>deep[edge[i].second])
		swap(edge[i].first,edge[i].second);
	for(i=1,all=1;i<=n;++i)
		all=(ll)all*fact[du[i]-1]%moder;
	ans=(ll)K*all%moder;
	for(i=1;i<K;++i) for(j=i+1;j<=K;++j) {
		x=lca(y=edge[p[i]].first,z=edge[p[j]].first);
		int ex=(lca(edge[p[i]].second,z)==edge[p[i]].second||lca(edge[p[j]].second,y)==edge[p[j]].second);
		int ttt=cnt[y]+cnt[z]-2*cnt[x]-ex;
		int gong=(ll)val[y]*val[z]%moder*invval[fa[x]]%moder*invval[x]%moder;
		gong=(ll)gong*all%moder*oinvval[y]%moder*oinvval[z]%moder*oval[fa[x]]%moder*oval[x]%moder;
		if(ttt==0) Sub(ans,gong);
	}
	printf("%d\n",ans);
	if(T) goto loop;
}
