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

using namespace std;

int main(){
    string str;
    map<string, string> charmsToFunction;
    map<string, string> functionToCharm;
    while(getline(cin,str)) {
        if (str == "@END@") {
            break;
        }

        int pos = str.find("]");
        string key = str.substr(1, pos - 1);
        string function = str.substr(pos + 2);
        charmsToFunction[key] = function;
        functionToCharm[function] = key;
    }
        int samples;
        scanf("%d\n",&samples);
        while(samples--){
            string s,answer;
            getline(cin,s);
            if(s[0]!='['){
                answer=functionToCharm[s];
            }else{
                int p=s.find("]");
                s=s.substr(1,p-1);
                answer=charmsToFunction[s];
            }
            if(answer==""){
                printf("what?\n");
            }else{
                cout<<answer<<endl;
            }
        }

    return 0;

}