#include <cstdio>
#include <iostream>
#include "unordered_map"
using namespace std;

int main() {
    string line;
    unordered_map<string, string> codeMap;
    unordered_map<string, string> meanMap;

    while (getline(cin, line)) { // 注意 while 处理多个 case
        // cout << a + b << endl;
        if (line == "@END@") {
            break;
        }
        string mean;
        int pos = line.find(']');
        string code = line.substr(1, pos-1);
        mean = line.substr(pos + 2);
        codeMap[code] = mean;
        meanMap[mean] = code;
    }
    int n;
    cin >> n;
    getchar();//吃掉回车
    while (n--) {
        string lookUp;
        getline(cin, lookUp);
        if (lookUp[0] == '[') {
            lookUp = lookUp.substr(1, lookUp.size() - 2);
            if (codeMap.find(lookUp) == codeMap.end()) {
                cout << "what?" << endl;
            } else {
                cout << codeMap[lookUp] << endl;
            }
        } else {
            if (meanMap.find(lookUp) == meanMap.end()) {
                cout << "what?" << endl;
            } else {
                cout << meanMap[lookUp] << endl;
            }
        }


    }
}
// 64 位输出请用 printf("%lld")