#include<bits/stdc++.h>
using namespace std;
#define int long long
const int maxn=1e5+10,Mod=1e9+7;
int d[maxn],c[maxn];
int read(){
	int x=0;char ch=getchar();
	while(ch<'0'||ch>'9') ch=getchar();
	while(ch>='0'&&ch<='9'){x=(x<<1)+(x<<3)+(ch^48);ch=getchar();}
	return x;
}
//void write(int x){
//	if(x>9) write(x/10);
//	putchar(x%10+'0');
//}
struct edge{
	int to,next;
}e[maxn<<1];
int head[maxn],cnt;
void add(int u,int v){
	e[++cnt].to=v;e[cnt].next=head[u];head[u]=cnt;
}
bool check(int n){
	for(int i=1;i<=n;i++)
		if(d[i]!=1&&d[i]!=2) return false;
	return true;
}
signed main(){
	freopen("traverse.in","r",stdin);
	freopen("traverse.out","w",stdout);
	int C,T;C=read();T=read();
	while(T--){
		int n,k;n=read();k=read();
		memset(d,0,sizeof(d));
		memset(e,0,sizeof(e));
		memset(head,0,sizeof(head));
		cnt=0;
		for(int i=1;i<n;i++){
			int u,v;u=read();v=read();
			d[u]++;d[v]++;add(u,v);add(v,u);
		}
		for(int i=1;i<=k;i++) c[i]=read();
		bool flag=check(n);
		if(flag){printf("1\n");continue;}
	}
	return 0;
}
