#include<bits/stdc++.h>
using namespace std;
const int MAXN=1e5+5;
int n,k,a[MAXN];
vector<int> ve[MAXN];
int read()
{
	char c=getchar();
	while(c<'0'||c>'9')c=getchar();
	while(c>='0'&&c<='9')c=getchar();
	return 0;
}
int main()
{
	freopen("traverse.in","r",stdin);
	freopen("traverse.out","w",stdout);
	int c,T;
	cin>>c>>T;
	if(c<=25)
	{
		while(T--)
		{
			cin>>n>>k;
			for(int i=1;i<n;i++)
			{
				read(),read();
			}
			for(int i=1;i<=k;i++)
			{
				read();
			}
			if(k)puts("1");
			else puts("0");
		}
	}
	return 0;
}
