/* Simon Gog */
#include <iostream>
#include <map>
#include <string>
#include <cctype>
#include <fstream>

using namespace std;

typedef map<string,string> tMS;

#define in cin

bool isVocal(char c){
	c = tolower(c);
	return c=='a' || c=='e' || c=='i' || c=='o' || c=='u';
}

int main(){
	int L,N;
	in>>L>>N;
	tMS mapi;
	for(int i=0; i<L; ++i)
	{
		string sgl,plr;
		in>>sgl>>plr;
		mapi[sgl]=plr;
	}
	for(int i=0; i<N; ++i)
	{
		string word;
		in>>word;
		int len = word.size();
		if( mapi.find(word)!=mapi.end() )
			cout<<mapi[word]<<endl;
		else if( len >1 && word[len-1]=='y' && !isVocal(word[len-2]) ){
			word[len-1] = 'i';
			cout<<word<<"es"<<endl;
		}
		else if( word[len-1] =='o' || word[len-1]=='s' ||
				 word[len-1] =='x' ||
				 ( word[len-2]=='c'  && word[len-1]=='h') ||
				 ( word[len-2]=='s'  && word[len-1]=='h')
			   )
		{
			cout<<word<<"es"<<endl;
		}
		else{
			cout<<word<<"s"<<endl;
		}
	}
}
