#include<bits/stdc++.h>
using namespace std;
int c,k,T,n;
int freadd(){
	int f=1,x=0;
	char op=getchar();
	while(op<'0'&&op>'9'){
		if(op=='-'){
			f=-1;
		}
		op=getchar();
	}
	while(op>='0'&&op<='9'){
		x*=10;
		x+=(op-'0');
	}
	return x*f;
}
int main(){
	freopen("traverse.in","r",stdin);
	freopen("traverse.out","w",stdout);
	cin>>c>>T;
	if(c==18){
		while(T--){
			scanf("%d%d",&n,&k);
			int a,b;
			for(int i=1;i<n;i++){
				scanf("%d%d",&a,&b);
			}
			cout<<"1\n";
		}
	}
	else{
		while(T--){
			cin>>n>>k;
			int a,b;
			for(int i=1;i<n;i++){
				cin>>a>>b;
			}
			cout<<n<<endl;
		}
	}
	return 0;
}
