#include<bits/stdc++.h>
using namespace std;
const int mod=1e9+7;
int t,c;
int n,k;
struct edge{
	int x;
	int y;
}eds[100010];
int e[100010];
vector<int>v[100010];
int frac(int x){
	int res=1;
	for(int i=1;i<=x;i++){
		res=res*i%mod;
	}
	return res;
}
int read(){
	int res=0;
	char c=getchar();
	while(c<'0'||c>'9')c=getchar();
	while(c>='0'&&c<='9'){
		res=res*10+c-'0';
		c=getchar();
	}
	return res;
}
int mx;
int main(){
	freopen("traverse.in","r",stdin);
	freopen("traverse.out","w",stdout);
	c=read();
	t=read();
	while(t--){
		n=read();
		k=read();
		for(int i=1;i<=n;i++){
			v[i].clear();
		}
		mx=0;
		for(int i=1;i<=n-1;i++){
			eds[i].x=read();
			eds[i].y=read();
			v[eds[i].x].push_back(i);
			v[eds[i].y].push_back(i);
		}
		for(int i=1;i<=n;i++){
			mx=max(mx,(int)v[i].size());
		}
		for(int i=1;i<=k;i++){
			e[i]=read();
		}
		if(n==2)cout<<"1\n";
		else if(n==3)cout<<"1\n";
		else if(n==4){
			if(mx==3){
				if(k==1)cout<<"2\n";
				else cout<<"3\n";
			}else cout<<"1\n";
		}else if(n==5&&mx==3){
			int cnt=0,bl=0,bbl=0;
			for(int i=1;i<=k;i++){
				if(max(v[eds[e[i]].x].size(),v[eds[e[i]].y].size())==3&&min(v[eds[e[i]].x].size(),v[eds[e[i]].y].size())==2){
					cnt+=4;
					bl=1;
				}
			}
			for(int i=1;i<=k;i++){
				if(max(v[eds[e[i]].x].size(),v[eds[e[i]].y].size())==3&&min(v[eds[e[i]].x].size(),v[eds[e[i]].y].size())==2){
					continue;
				}
				if(max(v[eds[e[i]].x].size(),v[eds[e[i]].y].size())==3){
					if(bl)cnt+=1;
					else cnt+=2;
					bbl++;
				}
			}
			for(int i=1;i<=k;i++){
				if(max(v[eds[e[i]].x].size(),v[eds[e[i]].y].size())==3){
					continue;
				}
				cnt+=2-bbl;
			}
			cout<<cnt<<"\n";
		}else if(c==18)cout<<"1\n";
		else if(19<=c&&c<=21||mx==n-1)cout<<(frac(n-1)*k%mod-k*(k-1)/2%mod*frac(n-2)%mod+mod)%mod<<"\n";
		else cout<<n-2<<"\n";
	}
}
//11:56 0~28pts expect 16pts
//I can not solve it
//what can I say,GD-1158 out!
