#include<bits/stdc++.h>
#define int long long
#define endl '\n'
using namespace std;

const int N = 3e5+10;
const int M = 1e9+7;
int n,m,k,a[N];
vector<int> vec[N];

inline int qpow(int base,int x){
	if(x<0) return 1;
	int tmp = 1;
	while(x){
		if(x&1) tmp = (tmp*base)%M;
		x >>= 1;
		base = (base*base)%M;
	}
	return tmp;
}

inline int dfs(int x,int fa){
	if(!vec[x].size()) return 1;
	int tmp = 1;
	for(int v:vec[x]){
		if(v==fa) continue;
		tmp = (tmp*dfs(v,x))%M;
	}
	int num = vec[x].size()-1;
	if(fa==0) num++;
	return (tmp*qpow(num,num-2))%M;
}

inline void work(){
	cin>>n>>k;
	int q1,q2;
	for(int i=1;i<n;i++){
		cin>>q1>>q2;
		vec[q1].push_back(q2);
		vec[q2].push_back(q1);
	}
	int ans = 0;
	for(int i=1;i<=k;i++){
		cin>>q1;
		ans = (ans+dfs(q1,0))%M;
	}
	cout<<ans;
}

signed main(){
	ios::sync_with_stdio(false);
	freopen("traverse.in","r",stdin);
	freopen("traverse.out","w",stdout);
	int c,t;
	cin>>c>>t;
	while(t--){
		work();
		for(int i=1;i<=n;i++) vec[i].clear();
	}
	
	return 0;
}
