/* Walter Guttmann */
#include <fstream>
#include <iostream>
#include <string>

using namespace std;

#define in cin
int main() {
  int l, n;
  in >> l >> n;
  string s, irr[2][256];
  for (int i=0 ; i<l ; i++)
    in >> irr[0][i] >> irr[1][i];
  for (int i=0 ; i<n ; i++) {
    in >> s;
    string last = s.substr(s.size()-1);
    string last1 = s.size() < 2 ? "" : s.substr(s.size()-2, 1);
    string last2 = s.size() < 2 ? "" : s.substr(s.size()-2);
    for (int j=0 ; j<l ; j++)
      if (irr[0][j] == s) {
        cout << irr[1][j] << endl;
        goto done;
      }
    if (last1 != "a" && last1 != "e" && last1 != "i" && last1 != "o" && last1 != "u" && last == "y")
      cout << s.substr(0, s.size()-1) << "ies" << endl;
    else if (last == "o" || last == "s" || last2 == "ch" || last2 == "sh" || last == "x")
      cout << s << "es" << endl;
    else
      cout << s << "s" << endl;
done:;
  }
  return 0;
}

