#include<bits/stdc++.h>
using namespace std;
int c,t,n,k,u,v,st;
int main(){
	freopen("traverse.in","r",stdin);
	freopen("traverse.out","w",stdout);
	scanf("%d%d",&c,&t);
	while(t--){
		scanf("%d%d",&n,&k);
		for(int i=1;i<n;i++) scanf("%d%d",&u,&v);
		for(int i=1;i<=k;i++) scanf("%d",&st);
		if(c==18) putchar('1');
		else putchar('0');
		putchar('\n');
	}
	return 0;
}
