#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll N=1e6+10;
ll n,q;string a[N],b[N],x,y;
int main()
{
	freopen("replace.in","r",stdin);
	freopen("replace.out","w",stdout);
	cin>>n>>q;
	for(ll i=1;i<=n;i++)cin>>a[i]>>b[i];
	while(q--)
	{
		cin>>x>>y;
		cout<<0<<endl;
	}
	return 0; 
}
