#include<cstdio>
#include<string>
#include<map>
using namespace std;
int main(){
map<string,string> dict;
//构建词典
while (true){
char line[200];
fgets(line,200,stdin);//输入一行
string linestr = line;//C-->C++
linestr.pop_back();//去掉末尾的换行符
if(linestr == "@END@"){
break;
}
string word = linestr.substr(0,linestr.find(']')+1);
string info = linestr.substr(linestr.find(']')+2);
dict[word] = info;
dict[info] = word;
}
int n;
scanf("%d",&n);
getchar();
for(int i = 0; i < n; ++i){
char line[200];
fgets(line,200,stdin);
string linestr = line;
linestr.pop_back();
if(dict.find(linestr) != dict.end()){
//存在某个魔咒或者功能
if(linestr[0] == '['){
//根据魔咒查找功能
printf("%s\n",dict[linestr].c_str());
}
else{
//根据功能找魔咒
printf("%s\n",dict[linestr].substr(1,dict[linestr].size()-2).c_str());
}
}
else{
printf("what?\n");
}
}
}