#include<bits/stdc++.h>
using namespace std;
int n,q,L,lena,minn=99999999,maxn,ans;
string s[200001][2],t1,t2;char a[10001];
int main()
{
	freopen("replace.in","r",stdin);
	freopen("replace.ans","w",stdout);
	cin>>n>>q;
	for(int i=1;i<=n;i++){cin>>s[i][0]>>s[i][1];}
	for(int i=1;i<=q;i++)
	{cin>>t1>>t2;
	/*
	 ans=0;
	 L=t1.length();
	 for(int j=1;j<=L;j++)
	 {
	 	if(t1[j]!=t2[j])
	 	{
	 		maxn=max(j,maxn);
	 		minn=min(j,minn);
		}
	 }
	 lena=maxn-minn+1;
	 for(int j=1;j<=n;j++)
	 	for(int g=1;g<=s[i][0].length();g++)
	 	{
	 		
		}
		*/
		cout<<0<<endl;
	}
	
	return 0;
 }

