#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <cstring>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#include <queue>
#include <stack>
#include <deque>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <functional>
typedef long long int ll;
using namespace std;
#define INF 1234567890
#define N 200000
const int LIMIT = 1e+9;
int n, m;
unordered_map<string, int> hash_map;
string s[100006];
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin >> n >> m;
for (int i = 1; i <= n; i++) {
cin >> s[i];
hash_map.insert({ s[i], i });
}
for (int i = 0; i < m; i++) {
string ms;
cin >> ms;
if ('A' <= ms[0] && ms[0] <= 'Z') {
cout << hash_map.find(ms) -> second << "\n";
}
else {
cout << s[atoi(ms.c_str())] << "\n";
}
}
return 0;
}