#include <iostream>
#include<map>
#include <vector>
using namespace std;
int main() {
string s1;
map<string, string>m1;
map<string, string>m2;
while (getline(cin, s1)) { // 注意 while 处理多个 case
if (s1 == "@END@")break;
int pos = s1.find(']');
string s2 = s1.substr(0, pos + 1);
string s3 = s1.substr(pos + 2, s1.length() - (pos + 2));
m1[s2] = s3;
m1[s3] = s2.substr(1, s2.length() - 2);
}
int N;
cin >> N;
cin.ignore();
for (int i = 0; i < N; i++) {
getline(cin, s1);
if (m1.find(s1) != m1.end()) {
cout << m1[s1] << endl;
} else {
printf("what?\n");
}
}
}
// 64 位输出请用 printf("%lld")