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