#include <bits/stdc++.h>

using namespace std;

int c,T;
int n,k;

int main(){
	freopen("traverse.in","r",stdin);
	freopen("traverse.out","w",stdout);
	scanf("%d %d",&c,&T);
	while(T--){
		scanf("%d %d",&n,&k);
		for(int i=1;i<n;++i){
			int u,v;
			scanf("%d %d",&u,&v);
		}
		for(int i=1;i<=k;++i){
			int u;
			scanf("%d",&u);
		}
		printf("%d\n",k);
	}
	return 0;
}
