#include <bits/stdc++.h>
using namespace std;
int c,T;
bool mapp[5000][5000];
int main(){
	freopen("traverse.in","r",stdin);
	freopen("traverse.out","w",stdout);
	scanf("%d %d",&c,&T);
	while(T--){
		int n,k; scanf("%d %d",&n,&k);
		memset(mapp,0,sizeof mapp);
		int cnt=0;
		for(int i=1;i<=n-1;++i){
			int u,v;
			scanf("%d %d",&u,&v);
			if(!mapp[u][v]) ++cnt;
			mapp[u][v]=1; mapp[v][u]=1;
		}
		for(int i=1;i<=k;++i){
			int tmp; cin >> tmp;
		}
		cout << cnt-1 << endl;
	}
} 
