#include<bits/stdc++.h>
using namespace std;
int main()
{
	freopen("replace.in","r",stdin);
	freopen("replace.out","w",stdout);
	int n,q;
	cin>>n>>q;
	string s1,s2,t1,t2;
	for(int i=1;i<=n;i++)
	  cin>>s1>>s2;
	for(int i=1;i<=q;i++)
	  cin>>t1>>t2;
	for(int i=1;i<=q;i++)
	  cout<<0<<endl;
	return 0;
} 
