#include<bits/stdc++.h>
using namespace std;
long long c,t,n,k,e;
int main(){
	freopen("traverse.in","r",stdin);
	freopen("traverse.out","w",stdout);
	cin>>c>>t;
	while(t--){
		cin>>n>>k;
		for(int i=1;i<n;i++){
			int u,v;
			cin>>u>>v;
		}
		for(int i=1;i<=k;i++){
			cin>>e;
		}
		cout<<k-1<<"\n";
	}
	return 0;
}
