#include <cstdio>
#include <vector>
#include <utility>
#include <cctype>
inline char gc() {
	static char buf[1<<20],*l,*r;
	return l==r&&(r=(l=buf)+fread(buf,1,1<<20,stdin),l==r)?-1:*l++;
}
template<class T> void read(T &&x) {
	x=0;
	char c=gc();
	bool neg=false;
	for(; !isdigit(c); c=gc()) if(c=='-') neg=true;
	for(; isdigit(c); c=gc()) x=(x<<1)+(x<<3)+(c&15);
	if(neg) x=-x;
}
using namespace std;
using ll = long long;
const int N = 1e5, P = 1e9 + 7;
int n,k,u[N + 2],v[N + 2],g[N + 2];
vector<pair<int,int>> e[N + 2];
ll f[N + 2];
ll dfs(int u,int p) {
	ll prod=1,cnt=0;
	for(auto [v,w] : e[u])
		if(w!=p) {
			(prod*=dfs(v,w))%=P;
			++cnt;
		}
	return prod*f[cnt]%P;
}
int main() {
	f[0]=1;
	for(int i=1; i<=N; ++i) f[i]=f[i-1]*i%P;
	freopen("traverse.in","r",stdin);
	freopen("traverse.out","w",stdout);
	int c,T;
	read(c),read(T);
	while(T--) {
		read(n),read(k);
		for(int i=1; i<n; ++i) {
			read(u[i]),read(v[i]);
			e[u[i]].emplace_back(v[i],i);
			e[v[i]].emplace_back(u[i],i);
		}
		for(int i=1; i<=k; ++i) read(g[i]);
		ll ans=0;
		if(c==18) {
			ans=1;
		} else if(19<=c&&c<=21) {
			ans=f[n-2]*k%P;
			if(k>1) ans=(ans-k*(k-1ll)/2%P*f[n-3]%P+P)%P;
		} else {
			for(int i=1; i<=1; ++i)
				(ans+=dfs(u[g[i]],g[i])*dfs(v[g[i]],g[i])%P)%=P;
		}
		printf("%lld\n",ans);
		for(int i=1; i<=n; ++i) e[i].clear();
	}
	return 0;
}