#include<bits/stdc++.h> 
using namespace std;
#define ll long long
const int N=5e5+10;
ll T,n,q;
struct Node{
	ll dep,fa,son;
}a[N];

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