#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N = 1e5+10;
int n,k,T,u[N],v[N],e[N];
signed main()
{
	freopen("traverse.in","r",stdin);
	freopen("traverse.out","w",stdout);
	scanf("%lld",&T);
	while(T--)
	{
		scanf("%lld%lld",&n,&k);
		for(int i = 1;i<n;i++)
			scanf("%lld%lld",&u[i],&v[i]);
		for(int i = 1;i<=k;i++)
			scanf("%lld",&e[i]);
		if(k==1)
		{
			puts("1");
			return 0;
		}
	}
	return 0;
}
