#include <iostream>
#include <cstdio>
#include <map>
#include <string>

using namespace std;

/**
 * 魔咒词典--浙江大学
 * @return
 */
int main() {
    map<string, string> curseMap;
    string curse;
    while (getline(cin, curse)) {
        //getchar();
        if (curse == "@END@") {
            break;
        }
        int pos = curse.find("]");
        /*
         * 补充substr(off, count):截取字符串,从指定位置off开始,并指定的长度count
         */
        string instruction = curse.substr(0, pos + 1);
        string function = curse.substr(pos + 2);
        /*
         * 以[魔咒]为key,功能为value
         * 以为功能key,[魔咒]为value
         */
        curseMap.insert(pair<string, string>(instruction, function));
        curseMap.insert(pair<string, string>(function, instruction));
    }
    int m;
    cin >> m;
    getchar();
    for (int i = 0; i < m; ++i) {
        string key;
        getline(cin, key);
        string ans = curseMap[key];
        if (ans == "") {
            /*
             * [魔咒]和功能都不存在
             */
            ans = "what?";
        } else if (ans[0] == '[') {
            /*
             * 功能存在,输出魔咒
             */
            ans = ans.substr(1, ans.size() - 2);
        }
        cout << ans << endl;
    }

    return 0;
}