#include <iostream>
#include <map>
#include <vector>
#include <algorithm>
#include <string>
using namespace std;
map<string, int> dictionary;
static bool comp(pair<string, int> &a, pair<string, int> &b)
{
return a.second < b.second;
}
int searchDict(string name)
{
return dictionary.find(name)->second;
}
int main(void)
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int N, M;
cin >> N >> M;
for (int i = 1; i <= N; i++)
{
string temp;
cin >> temp;
dictionary.insert({temp, i});
}
vector<pair<string, int>> dicVec(dictionary.begin(), dictionary.end());
sort(dicVec.begin(), dicVec.end(), comp);
for (int i = 1; i <= M; i++)
{
string temp;
cin >> temp;
if (temp[0] < 65)
{
int num = stoi(temp);
cout << dicVec[num - 1].first << '\n';
}
else
{
cout << searchDict(temp) << '\n';
}
}
}
Coding/BaekJoon