#include<bits/stdc++.h>
using namespace std;
using ll=long long;
const ll N=1e4+10;
ll n,q;
string s[N][2];
int main(){
	freopen("replace.in","r",stdin);
	freopen("replace.out","w",stdout);
	cin>>n>>q;
	for(ll i=1;i<=n;i++)
		cin>>s[i][0]>>s[i][1];
	while(q--){
		string t1,t2;
		cin>>t1>>t2;
		cout<<0<<"\n";
	}
	return 0;
}
