#include<string>
#include<iostream>
#include<set>
#include<cctype>
#include<map>
using namespace std;
int main()
{
string temp;
set<string>no_key;
multimap<string,string>key_title;
while(getline(cin,temp)&&temp!="::")
no_key.insert(temp);
int temp1=0,temp2=0,i,j;
string temp_str="";
while(getline(cin,temp))
{
temp.insert(0,"*");
temp.insert(temp.length(),"*");
for(i=0;i<temp.length();i++)
temp[i]=tolower(temp[i]);
for(i=1;i<temp.length();i++)
{
if(isalpha(temp[i])&&!isalpha(temp[i-1]))
temp1=i;
if(isalpha(temp[i])&&!isalpha(temp[i+1]))
temp2=i;
if(temp1&&temp2)
{
temp_str=temp.substr(temp1,temp2-temp1+1);
if(!no_key.count(temp_str))
{
string t(temp);
for(j=0;j<temp_str.length();j++)
temp_str[j]=toupper(temp_str[j]);
t.replace(temp1,temp_str.size(),temp_str);
t.erase(0,1);
t.erase(t.length()-1,1);
key_title.insert(make_pair(temp_str,t));
}
temp_str="";
temp1=0;
temp2=0;
}
}
}
multimap<string,string>::iterator it;
for(it=key_title.begin();it!=key_title.end();it++)
cout<<it->second<<endl;
return 0;
}