#include<bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
#define vi vector<int>
#define pb push_back
#define lowbit(x) x&-x
using namespace std;
const int N=1e5+10;
const int mod=1e9+7;
struct node{
	int u,v;
}e[N];
int ans;
vector<pii> G[N];
int n,m,T,v[N],tag[N],f[N],fac[N],c,typ[N],inv[N];
inline int read(){
	int s=0,f=0;
	char ch=getchar();
	while(ch<'0'||ch>'9') f|=(ch=='-'),ch=getchar();
	while(ch<='9'&&ch>='0') s=(s<<3)+(s<<1)+(ch^48),ch=getchar();
	return f?-s:s;
}
inline int qpow(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;
}
inline void dfs(int x,int fa){
	int siz=0,tmp=0;
	f[x]=1;typ[x]=0;
	for(pii e:G[x]){
		int to=e.first;
		if(to==fa) continue;
		dfs(to,x);
		f[x]=1ll*f[x]*f[to]%mod;
		++siz;
		if(tag[e.second]||typ[to]) ++tmp;
	}
	f[x]=1ll*f[x]*fac[siz-tmp]%mod;
	if(tmp>1) f[x]=0;
	if(tmp) typ[x]=1;
}
int main(){
	freopen("traverse.in","r",stdin);
	freopen("traverse.out","w",stdout);
	c=read(),T=read();
	fac[0]=inv[0]=1;
	for(register int i=1;i<N;++i) fac[i]=1ll*fac[i-1]*i%mod,inv[i]=qpow(fac[i],mod-2);
	while(T--){
		n=read(),m=read();
		for(register int i=1;i<=n;++i) G[i].clear();
		for(register int i=1;i<n;++i){
			int u=read(),v=read();
			e[i]={u,v};
			G[u].pb({v,i}),G[v].pb({u,i});
		}
		for(register int i=0;i<m;++i) v[i]=read();
		if(c==18) cout<<1<<'\n';
		else if(c>=19&&c<=21){
			if(n==2) cout<<1<<'\n';
			else cout<<(1ll*m*fac[n-2]%mod-1ll*m*(m-1)/2%mod*fac[n-3]%mod+mod)%mod<<'\n';
		}else if(c<=12){
			ans=0;
			for(register int S=1;S<(1<<m);++S){
				int pos=0;
				for(register int i=0;i<m;++i) if(S>>i&1) tag[v[i]]=1,pos=v[i];
				int x=e[pos].u,y=e[pos].v;
				dfs(x,y),dfs(y,x);
				for(register int i=0;i<m;++i) if(S>>i&1) tag[v[i]]=0;
				int res=1ll*f[x]*f[y]%mod;
				if(__builtin_popcount(S)&1) ans=(ans+res)%mod;
				else ans=(ans-res+mod)%mod;
			}
			cout<<ans<<'\n';
		}
	}
	return 0;
}
