#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N=1e5+5,mod=1e9+7;
int c,t,n,k,ans,a[N],siz[N];
struct node{
	int v,id;
};vector<int> G[N];
void dfs(int x,int fa){
	for(int i=0;i<G[x].size();i++){
		int v=G[x][i];
		if(v==fa) continue;
		dfs(v,x);
		siz[x]+=siz[v];
	}
	siz[x]+=(G[x].size()-2)*(G[x].size()-1)%mod;
}
int main(){
	freopen("traverse.in","r",stdin);
	freopen("traverse.out","w",stdout);
	cin>>c>>t;
	while(t--){
		cin>>n>>k;ans=0;
		for(int i=1;i<n;i++){
			int u,v;
			cin>>u>>v;
			G[u].push_back(v);G[v].push_back(u);
			a[i]=u;
		}
		for(int i=1;i<=k;i++){
			int s;memset(siz,0,sizeof siz);
			cin>>s;
			dfs(a[s],0);
			ans+=siz[a[s]]%mod;
		}
		cout<<ans%mod<<endl;
	}
	return 0;
}
/*
7 1
5 2
1 2
1 3
2 4
2 5
1 3

*/
