#include <bits/stdc++.h> 
using namespace std;
#define fastIO ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define int long long
const int N = 100003;
const int mod = 1000000007;
int testID,T;
int n,k,ans;
int dp[N],pw[N];
bool vis[N];
struct Edge{
	int x,y;
}e[N];
int dfs(int x){ int ret=1,num=0;
	vis[x]=1;
	for(int i=1;i<n;i++){
		if(e[x].x==e[i].x||e[x].y==e[i].x||e[x].x==e[i].y||e[x].y==e[i].y){
			if(!vis[i]){
				num++;ret=ret*dfs(i)%mod; 
			}
		}
	}
	vis[x]=0;
	return ret*pw[num]%mod;
}
void Main(){
	cin >> n >> k;
	for(int i=1;i<=n;i++){
		pw[i]=pw[i-1]*i%mod;
	}
	for(int i=1;i<n;i++){
		cin >> e[i].x >> e[i].y;
	}
	ans=0;
	for(int i=1,x;i<=k;i++){ cin>>x;
		ans+=dfs(i);
	}
	cout << ans << endl;
}
signed main(){ freopen("traverse.in","r",stdin); freopen("traverse.out","w",stdout); fastIO;
	cin >> testID >> T;
	while(T--) Main();
	return 0;
}
