/* Peter Schaeffer */
#include <stdio.h>
#include <string.h>

FILE *IN;
char dict[20][2][24];
int n, l;

int main()
{
  IN=stdin;
  fscanf(IN, " %d %d ", &l, &n);
  for(int i=0; i<l; i++)
    fscanf(IN, " %s %s ", dict[i][0], dict[i][1]);
  for(int i=0; i<n; i++)
    {
      char dummy[24];
      fscanf(IN, " %s ", dummy);
      int x=strlen(dummy);
      for(int j=0; j<l; j++)
	if (!strcmp(dummy, dict[j][0]))
	  {
	    printf("%s\n", dict[j][1]);
	    goto weiter;
	  }
      if ((x>=2) &&
	  ((dummy[x-2]!='a') &&(dummy[x-2]!='i') &&(dummy[x-2]!='u') &&(dummy[x-2]!='e') &&(dummy[x-2]!='o')) &&
	  (dummy[x-1]=='y'))
	{
	  dummy[x-1]='i';
	  printf("%ses\n", dummy);
	}
      else if ((x>=1) && ((dummy[x-1]=='o') ||
			  (dummy[x-1]=='s') ||
			  (dummy[x-1]=='x') ||
			  ((x>=2) && (dummy[x-2]=='s') && (dummy[x-1]=='h')) ||
			  ((x>=2) && (dummy[x-2]=='c') && (dummy[x-1]=='h'))))
	printf("%ses\n", dummy);
      else
	printf("%ss\n", dummy);
    weiter:;
    }
  return 0;
}
