#include <iostream>
#include <map>
#include <string>
using namespace std;
map<string,string> wizd;
int main() {
string x;
wizd.clear();
while(getline(cin, x) && x!="@END@"){
int p=x.find(']');
wizd[x.substr(0,p+1)]=x.substr(p+2);
wizd[x.substr(p+2)]=x.substr(0,p+1);
}
int n;
cin>>n;
getchar();
for(int i=0;i<n;i++){
string lookup;
getline(cin,lookup);
if(wizd[lookup]=="") cout<<"what?"<<endl;
else {
string o=wizd[lookup];
if(o[0]=='['){
cout<<o.substr(1,o.find(']')-1)<<endl;
}
else cout<<o<<endl;
}
}
}