#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int N=1e3;
int n,q;
string s;
int main(){
	freopen("replace.in","r",stdin);
	freopen("replace.out","w",stdout);
	srand(time(0));
	cin>>n>>q;
	cin>>s;
	cin>>s;
	for(int i=1;i<=n;i++){
		cin>>s;
		cin>>s;
	}
	while(q--){
		cin>>s;
		cin>>s;
		cout<<rand()%10000+1<<'\n';
	}
	
	return 0;
}
