/* Author: Adrian Kuegel
Date: 14. 6. 2007
*/

#include <stdio.h>
#include <string.h>
#include <assert.h>

#define MAXSPECIAL 20

char singular[MAXSPECIAL][21], plural[MAXSPECIAL][21];
int l;

bool isvowel(char c) {
	return c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u';
}

void print_plural(char *s) {
	int len = strlen(s);
	if (s[len-1] == '\n')
		s[--len] = 0;
	assert(len > 0 && len <= 20);
	// check if it is a irregular word
	for (int i=0; i<l; ++i)
		if (!strcmp(s,singular[i])) {
			puts(plural[i]);
			return;
		}
	if (len > 1 && s[len-1] == 'y' && !isvowel(s[len-2])) {
		s[len-1] = 0;
		printf("%sies\n",s);
	}
	else if (s[len-1] == 'o' || s[len-1] == 's' || s[len-1] == 'x' || len > 1 && (s[len-2] == 's' && s[len-1] == 'h' || s[len-2] == 'c' && s[len-1] == 'h'))
		printf("%ses\n",s);
	else
		printf("%ss\n",s);
}

int main() {
	char word[100];
	int n;
	fgets(word,sizeof(word),stdin);
	assert(sscanf(word,"%d %d",&l,&n) == 2);
	assert(l >= 0 && l <= 20);
	assert(n >= 1 && n <= 100);
	for (int i=0; i<l; ++i) {
		fgets(word,sizeof(word),stdin);
		assert(sscanf(word,"%s %s",singular[i],plural[i]) == 2);
	}
	while(n--) {
		assert(fgets(word,sizeof(word),stdin));
		print_plural(word);
	}
	return 0;
}
