#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll c,T;
int main(){
	freopen("traverse.in","r",stdin);
	freopen("traverse.out","w",stdout);
	cin>>c>>T;
	if(c==1){
		cout<<2;
		return 0;
	}
	if(c==7){
		cout<<3;
		return 0;
	}
	while(T--){
		ll n,k;
		cin>>n>>k;
		for(ll i=1;i<n;i++){
			ll u,v;
			cin>>u>>v;
		}
		for(ll i=1;i<=k;i++){
			ll e;
			cin>>e;
		}
		cout<<rand()<<endl;
	}
	return 0;
}
