#include <bits/stdc++.h>
#define MAXN 100005
using ll = long long;
using namespace std;
//I want to ask if you love the world.
const int mod = 1e9+7;
bool s1;
ll qpow(ll x,ll k){
	ll ret=1;
	while(k){
		if(k&1)ret=ret*x%mod;
		x=x*x%mod; k>>=1;
	}return ret;
}
int n,k,e[MAXN],tstc;
ll fac[MAXN];
vector<int> vec[MAXN];
bool vis[1<<21];
int tmp[MAXN],top;
int ans;
struct edge{
	int u,v;
}g[MAXN];
int getp(int x){
	return (n)*(g[x].u-1)+g[x].v;
}
void getNxt(vector<int>& nxt,int S,int cur){
	for(int i=1;i<n;i++){
		if(i==cur)continue;
		if(g[i].u==g[cur].u || g[i].v==g[cur].v || g[i].u==g[cur].v || g[i].v==g[cur].u){
			//common dots
			if((S>>getp(i))&1)continue;
			//else can be
			nxt.push_back(i);
		}
	}
}
void dfs(int S){
	if(__builtin_popcount(S)==n-2){
		if(!vis[S]){
			ans++;vis[S]=1;
			
			//for(int i=1;i<n;i++){
			//	if((S>>getp(i))&1)cerr<<"("<<g[i].u<<","<<g[i].v<<") "; 
			//}
			//cerr<<"\n";
			
		}
		return;
	}
	vector<int> nxt;
	getNxt(nxt,S,tmp[top]);
	while(nxt.size()==0){
		getNxt(nxt,S,tmp[--top]);
	}
	vector<int> tp(n,0);
	int ctop=top;
	for(int i=1;i<=top;i++)tp[i]=tmp[i];
	for(int i : nxt){
		tmp[++top]=i;
		dfs(S|(1<<getp(i)));
		for(int i=1;i<=ctop;i++)tmp[i]=tp[i];
		top=ctop;
	}
}
bool s2;
inline int read();
void solve(){
	n=read(),k=read();
	for(int i=1;i<=n;i++)vec[i].clear();
	for(int i=1;i<n;i++){
		int u=read(),v=read();
		vec[u].push_back(v);
		vec[v].push_back(u);
		if(u>v)swap(u,v);
		g[i]={u,v};
	} 
	for(int i=1;i<=k;i++)e[i]=read();
	if(n==2){
		printf("1\n");
		return; 
	}
	if(tstc>=19 && tstc<=21){
		ll ans = fac[n-2]*k%mod;
		ll tmp = 1ll*k*(k-1)/2;
		ans -= tmp%mod*fac[n-3]%mod;
		ans=(ans%mod+mod)%mod;
		printf("%lld\n",ans);
		return;
	}
	if(tstc==18){
		printf("1\n");
		return; 
	}
	ans=0;
	memset(vis,0,sizeof vis);
	for(int i=1;i<=k;i++){
		top=1;
		tmp[1]=e[i];
		dfs(getp(e[i]));
	}
	printf("%d\n",ans);
}
int main(){
	freopen("traverse.in","r",stdin);
	freopen("traverse.out","w",stdout);
	cerr<<(&s1-&s2)/1024.0/1024<<"MB\n";
	fac[0]=1;
	for(int i=1;i<MAXN;i++)fac[i]=fac[i-1]*i%mod;
	tstc=read();
	int T=read();while(T--)solve();
	return 0;
} 
inline int read(){
	int x=0; char ch = getchar();
	while(ch<'0' && ch>'9')ch=getchar();
	while(ch>='0' && ch<='9')x=x*10+ch-'0',ch=getchar();
	return x; 
}
