#include<bits/stdc++.h>
using namespace std;
int cc,T,n,k,x,y;
int main(){
	freopen("traverse.in","r",stdin);
	freopen("traverse.out","w",stdout);
	cin>>cc>>T;
	while(T--){
		cin>>n>>k;
		for(int i=1; i<n; i++){
			scanf("%d%d", &x, &y);
			
		}
		for(int i=1; i<=k; i++)scanf("%d", &x);
		printf("%d\n", n-1);
	}
	return 0;
}
