#include<bits/stdc++.h>
using namespace std;
/*
1 1
4 1
1 2
2 3
2 4
1
*/
/*
7 1
5 2
1 2
1 3
2 4
2 5
1 3
*/
struct node{
	int v,x;
};
vector<node>e[100005];
int u[100005],v[100005],ans;
bool vis[100005];
void dfs(int x){
	ans++;
	for(int i=0;i<e[x].size();i++){
		int y=e[x][i].v,c=e[x][i].x;
		if(vis[c])continue;
		vis[c]=1;
		dfs(y);
	}
}
int main(){
	freopen("traverse.in","r",stdin);
	freopen("traverse.out","w",stdout);
	int id,t;
	cin>>id>>t;
	while(t--){
		int n,k,res=0;
		cin>>n>>k;
		for(int i=1;i<n;i++){
			cin>>u[i]>>v[i];
			e[u[i]].push_back({v[i],i});
			e[v[i]].push_back({u[i],i});
		}
		for(int i=1;i<=k;i++){
			memset(vis,0,sizeof(vis));
			int x;
			cin>>x;
			vis[x]=1;
			ans=0;
			dfs(u[x]);
			res+=ans-1;
			ans=0;
			dfs(v[x]);
			res+=ans-1;
			vis[x]=0;
		}
		cout<<res<<"\n";
	}
	return 0;
}
