//土尔逊Torson 编写于2023/06/13
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <string>
#include <map>

using namespace std;

map<string, string> dictionary;

int main() {
	string str;
	while (getline(cin, str)) {
		if (str == "@END@") {
			break;
		}
		int pos = str.find("]");             //分界点
		string key = str.substr(0, pos + 1); //魔咒
		string value = str.substr(pos + 2);  //功能
		dictionary[key] = value;
		dictionary[value] = key;
	}
	int n;
	scanf("%d", &n);
	getchar();                               //吃掉回车
	while (n--) {
		string key;
		getline(cin, key);
		string answer = dictionary[key];
		if (answer == "") {                  //魔咒或者功能找不到
			answer = "what?";
		}
		else if (answer[0] == '[') {         //魔咒需要删除方括号
			answer = answer.substr(1, answer.size() - 2);
		}
		cout << answer << endl;
	}
	system("pause");
	return EXIT_SUCCESS;
}
// 64 位输出请用 printf("%lld")