#include <bits/stdc++.h>
#include <cstdio>
using namespace std;
int main(){
	map<string ,string>mp;
	int n;
	while(true){
		char line[100];
		fgets(line,100,stdin);//读取一行 
		string s1 = line;
        s1.pop_back();
		if(s1=="@END@")	 break;
		string word = s1.substr(0,s1.find(']')+1);//截取从0开始到 s1.find(']')+1这么长的子串 
		string info = s1.substr(s1.find(']')+2);//截取从s1.find(']')+2下标开始一直到结尾 
		mp[word] =  info;
		mp[info] =  word;//双向建立映射 
		
	}
	cin>>n;
	getchar();//注意要加这句处理换行 
	for(int i=0;i<n;i++){
		char line[100];
		fgets(line,100,stdin);//读取一行 
		string s = line;
        s.pop_back();
		if(mp.find(s)!=mp.end()){
			if(s[0]=='[') cout<<mp[s]<<endl;
			else cout<<mp[s].substr(1,mp[s].size()-2)<<endl;
		}else{
			cout<<"what?"<<endl;
		}
	}
	
	return 0;
	
}