#include
//转小写
char tolower( char c)
{
if( c >='A'&c<='Z')
return c-'A'+'a';
}
//大小写敏感
bool findstr( char * instr, char * findstr)
{
char *s = instr;
char *t ;
while(1)
{
t = findstr;
while( *s != *t *s != '')
s++;
if( *s == '')
return false;
while( *t == *s *t != '' *s !='')
s++,t++;
if(*t == '')
return true;
}
}
//大小写不敏感
bool findstr_i( char * instr, char * findstr)
{
char *s = instr;
char *t ;
while(1)
{
t = findstr;
while( tolower(*s) != tolower(*t) *s != '')
s++;
if( *s == '')
return false;
while( tolower(*s) == tolower(*t) *t != '' *s !='')
s++,t++;
if(*t == '')
return true;
}
}
//主函数
int main()
{
char str[100];
char tarstr[100];
intcount;
intflag;
inti;
scanf("%s",str);
scanf("%d",&flag);
scanf("%d",&count);
for( i = 0;i< count;i++)
{
scanf("%s",tarstr);
if( 1 == flag findstr( tarstr, str))
printf("%sn",tarstr);
if( 0 == flag findstr_i( tarstr, str))
printf("%sn",tarstr);
}
::fflush(stdin);
getchar();
return 0;
}