#include <iostream>
#include <map>
using namespace std;

map<string, string> magics;

int main() {
    string str;
    while (getline(cin, str) && str != "@END@") {
        int pos = str.find(']');
        string s1 = str.substr(0, pos + 1);
        string s2 = str.substr(pos + 2);
        magics[s1] = s2;
        magics[s2] = s1;
    }

    int n;
    cin >> n;
    getchar();//帮getline吃掉回车
    while(n --){
        getline(cin, str);
        string res = magics[str];
        if(res == "")
            cout << "what?" << endl;
        else{
            if(res[0] == '[')
                cout << res.substr(1, res.size() - 2) << endl;
            else
                cout << res << endl;
        }
    }

    return 0;
}