/* Robin Nittka */
#include <iostream>
#include <fcntl.h>
#include <cstdio>
#include <string>
#include <map>
#include <unistd.h>

using namespace std;

inline char last(const string &s)
{
	return s[s.size()-1];
}

inline char last2(const string &s)
{
	return s[s.size()-2];
}

inline bool iscons(const char ch)
{
	switch (ch)
	{
	case 'a': ;
	case 'e': ;
	case 'i': ;
	case 'o': ;
	case 'u': ;
		return false;
	default:
		return true;
	}
}

int main()
{
	int L, N;
	cin >> L >> N;
	map<string,string> dict;
	for (int i = 0; i < L; i++)
	{
		string a, b;
		cin >> a >> b;
		dict[a] = b;
	}
	for (int i = 0; i < N; i++)
	{
		string s;
		cin >> s;
		if (dict.find(s) != dict.end())
		{
			cout << dict[s] << endl;
		}
		else if (s.size() >= 2 && s[s.size()-1] == 'y' && iscons(s[s.size()-2]))
		{
			cout << s.substr(0, s.size()-1) + "ies" << endl;
		}
		else if ((s.size() >= 1 && (last(s) == 'o' || last(s) == 's' || last(s) == 'x')) || (s.size() >= 2 && (last2(s) == 'c' && last(s) == 'h' || last2(s) == 's' && last(s) == 'h')))
		{
			cout << s + "es" << endl;
		}
		else
		{
			cout << s + "s" << endl;
		}
	}
	return 0;
}
