#include<bits/stdc++.h>
using namespace std;
int r(){
	int ans=0,f=1;
	char c=getchar();
	while(c<'0'||c>'9'){
		if(f=='-') f*=-1;
		c=getchar();
	}
	do{
		ans=ans*10+c-'0';
		c=getchar();
	}while(c>='0'&&c<='9');
	return ans;
} 
int main(){
	freopen("traverse.in","r",stdin);
	freopen("traverse.out","w",stdout);
	int c,T;
	int n,k;
	cin>>c>>T;
	while(T--){
		cin>>n>>k;
		for(int i=1;i<=n-1;i++){
			c=r();
			c=r();
		}
		for(int i=1;i<=k;i++){
			c=r();
		}
		cout<<1<<endl;
	}
	return 0;
} 
