#include <iostream>
#include <string>
#include <map>
using namespace std;
int main() {
string s;
map<string, string> maps; // 创建一个map,用于存储魔咒与对应功能的映射关系
while (getline(cin, s)) {
if (s == "@END@") { // 输入以"@END@"结束,退出循环
break;
}
int pos = s.find(']');
string s1 = s.substr(0, pos + 1); // 提取魔咒部分,包括中括号
string s2 = s.substr(pos + 2); // 提取功能部分,去除空格
maps[s1] = s2; // 将魔咒与功能的映射关系存入map
maps[s2] = s1; // 将功能与魔咒的映射关系存入map
}
int n;
cin >> n;
cin.ignore(); // 忽略掉之前输入时的换行符
for (int i = 0; i < n; i++) {
string ss;
getline(cin, ss); // 读取一个测试用例
if (maps.find(ss) == maps.end()) { // 如果魔咒不在词典中
cout << "what?" << endl; // 输出"what?"
}
else if (maps[ss][0] == '[') { // 如果找到的映射值以'['开头,说明ss是功能,不是魔咒
cout << maps[ss].substr(1, maps[ss].size() - 2) << endl; // 输出功能,去掉中括号
}
else {
cout << maps[ss] << endl; // 输出魔咒对应的功能
}
}
return 0;
}