/* Christoph Schwirzer */
#include <cstdio>
#include <iostream>
#include <map>
using namespace std;
typedef map<string, string> MSS;
MSS mp;
bool isvowel(char ch)
{
	switch (ch)
	{
		case 'a':
		case 'e':
		case 'i':
		case 'o':
		case 'u':
			return true;
	}
	return false;
}
bool isconsonant(char ch)
{
	return !isvowel(ch);
}
bool endswith(const string &s, const string &t)
{
	if (s.size() < t.size())
		return false;
	return s.substr(s.size() - t.size()) == t;
}
string plural(const string &s)
{
	MSS::iterator it = mp.find(s);
	if (it != mp.end())
		return it->second;
	int n = s.size();
	if (n >= 2 && isconsonant(s[n-2]) && s[n-1] == 'y')
		return s.substr(0, n-1) + "ies";
	if (endswith(s, "o") ||	endswith(s, "s") ||	endswith(s, "ch") ||	endswith(s, "sh") || endswith(s, "x"))
		return s + "es";
	return s + "s";
}
int main()
{
	int m, n;
	cin >> m >> n;
	for (int i=0; i<m; i++)
	{
		string a, b;
		cin >> a >> b;
		mp[a] = b;
	}
	for (int i=0; i<n; i++)
	{
		string s;
		cin >> s;
		cout << plural(s) << endl;
	}
	return 0;
}
