//replace
//16��53��--17��01�� 
//crx
/*

KMP 

���Ƶ÷�:0

*/
#include<bits/stdc++.h>
#define ll long long
using namespace std;

int n,q;

int main(){
	freopen("replace.in","r",stdin);
	freopen("replace.out","w",stdout);
	cin>>n>>q;
	for(int i=1;i<=n;i++){
		string s;
		cin>>s;
		cin>>s;
	}
	for(int i=1;i<=q;i++){
		string t;
		cin>>t;
		cin>>t;
		cout<<0<<'\n';
	}
	fclose(stdin);
	fclose(stdout);
	return 0;
}

