#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N=1e5+5;
const int mod=1e9+7;
inline void read(int &x){
	char ch=getchar();
	int q=1;x=0;
	while(ch<'0'||ch>'9'){
		if(ch=='-'){
			q=-1;
		}
		ch=getchar();
	}
	while(ch>='0'&&ch<='9'){
		x=x*10+(ch-'0');
		ch=getchar();
	}
	x=x*q;
	return;
}
int p[N];
struct edge{
	int v,id;
};
vector<edge>e[N];
int b[505][505];
int n,k;
int work1(){
	p[1]=1;
	for(int i=2;i<=n;i++){
		p[i]=p[i-1]*i%mod;
	}
	int res=0;
	for(int i=1;i<=k;i++){
		res=res+p[n-i]%mod;
		res=res%mod;
	}
	return res;
}
void build(){
	int tmp[505],len;
	for(int i=1;i<=n;i++){
		len=0;
		for(auto j:e[i]){
			tmp[++len]=j.id;
		}
		for(int j=1;j<=len;j++){
			for(int jj=1;jj<=len;jj++){
				if(j!=jj){
					b[j][jj]=1;
					b[jj][j]=1;
				}
			}
		}
	}
	return;
}
int work(){
	build();
	
}
signed main(){
	freopen("traverse.in","r",stdin);
	freopen("traverse.out","w",stdout);
	int T,c;
	read(c),read(T);
	while(T--){
		read(n),read(k);
		int u,v;
		for(int i=1;i<=n;i++){
			e[i].clear();
		}
		for(int i=1;i<n;i++){
			read(u),read(v);
			e[u].push_back({v,i});
			e[v].push_back({u,i});
		}
		int x;
		for(int i=1;i<=k;i++){
			read(x);
		}
		if(c==18){
			cout<<1<<"\n";
			continue;
		}
		if(c==19||c==20||c==21){
			cout<<work1()<<"\n";
			continue;
		}
		cout<<work()<<"\n";
	}
	return 0;
}
