/* Manfred Sauter */
#include <iostream>
#include <fstream>
#include <map>
#include <string>
using namespace std;


typedef map<string, string> tMSS;

#define in cin

string end_es[] = { "o", "s", "ch", "sh", "x" };


bool match_es(string word)
{
	for (int i=0; i<5; i++)
	{
		string test = end_es[i];
		if (word.length() >= test.length())
		{
			string str = word.substr(word.length()-test.length());
			if (str == test) return true;
		}
	}
	return false;
}

string vowels = "aeiou";

bool match_y(string word)
{
	int len = word.length();
	if (len < 2) return false;

	char last = word[len-1];
	if (last == 'y')
	{
		if (vowels.find(word[len-2]) == string::npos) return true;
	}
	return false;
}


int main()
{
	int L, N;
	in >> L >> N;
	tMSS mp;
	for (int i=0; i<L; i++)
	{
		string from, to;
		in >> from >> to;
		mp[from] = to;
	}

	for (int i=0; i<N; i++)
	{
		string word;
		in >> word;

		if (mp.find(word) != mp.end())
		{
			word = mp[word];
		}
		else if (match_y(word))
		{
			word = word.substr(0, word.length()-1) + "ies";
		}
		else if (match_es(word))
		{
			word += "es";
		}
		else
		{
			word += "s";
		}
		cout << word << endl;
	}

	return 0;
}


