#include<bits/stdc++.h>
const int mod=1e9+7;
using namespace std;
int c,t,n,k,u[100005],v[100005],e;
int vis[100005];
long long anss;
vector<int>G[100005];
int dfs(int id,int fa){
	long long ans=1,num=0;
	vis[id]=1;
	if(u[id]!=fa){
		for(auto p:G[u[id]]){
			if(vis[p]==0)num++,ans=(ans*dfs(p,u[id]))%mod;
		}
	}
	if(v[id]!=fa){
		for(auto p:G[v[id]]){
			if(vis[p]==0)num++,ans=(ans*dfs(p,v[id]))%mod;
		}
	}
	for(int x=num;x>1;x--){
		ans*=x;
		ans%=mod;
	}
	return ans%mod;
}
int main(){
	freopen("traverse.in","r",stdin);
	freopen("traverse.out","w",stdout);
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin>>c>>t;
	while(t--){
		cin>>n>>k;
		for(int x=1;x<=n;x++)G[x].clear();
		for(int x=1;x<n;x++){
			cin>>u[x]>>v[x];
			G[u[x]].push_back(x);
			G[v[x]].push_back(x);
		}
		anss=0;
		for(int x=1;x<=k;x++){
			fill(vis+1,vis+n+1,0);
			cin>>e;
			anss+=dfs(e,0);
		}
		cout<<anss<<"\n";
	}
	return 0;
}
