#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int N=1e6+10;
const int M=1e3+10;
const int INF=0x3f3f3f3f;
int c,T;
int n,k,ans,m,start;
bool vis[N];
struct node{
	int a,b,id;
}tr[N];
signed main(){
	freopen("traverse.in","r",stdin);
	freopen("traverse.out","w",stdout);
	cin>>c>>T;
	while(T--){
		cin>>n>>k;
		m=n-1,ans=0,start;
		for(int i=1,u,v;i<=m;i++){
			cin>>tr[i].a>>tr[i].b;
		}
		for(int i=1;i<=k;i++)cin>>start;
		cout<<n-2<<endl;
	}
}



