#include<bits/stdc++.h>
using namespace std;
#define int long long
const int mod = 1e9+10;
const int maxn = 1e5+10;
int c,t,n,k,u,v,e;
signed main(){
	freopen("traverse.in","r",stdin);
	freopen("traverse.out","w",stdout);
	cin>>c>>t;
	while(t--){
		cin>>n>>k;
		for(int i=1;i<=n-1;i++){
			cin>>u>>v;
		}
		for(int i=1;i<=k;i++){
			cin>>e;
		}
		if(c==18){
			cout<<1<<endl;
		}
		if(c==19||c==20||c==21){
			cout<<0<<endl;
		}
	}
}

