#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <string>
#include <unordered_map>
using namespace std;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
//freopen("input.txt", "rt", stdin);
unordered_map<string, string> uMap;
int N{}, M{};
cin >> N >> M;
string address, password;
for (int i = 0; i < N; ++i)
{
cin >> address >> password;
uMap[address] = password;
}
for (int i = 0; i < M; ++i)
{
cin >> address;
cout << uMap[address] << '\n';
}
return 0;
}