#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  unordered_map<string, string> dict;
  string lecture[n], s1, s2;
  for (int i = 0; i < m; i++) {
    cin >> s1 >> s2;
    dict[s1] = s2;
  }
  for (int i = 0; i < n; i++) {
    cin >> lecture[i];
    if (dict.find(lecture[i]) != dict.end()) {
      if (dict[lecture[i]].size() < lecture[i].size()) {
        lecture[i] = dict[lecture[i]];
      }
    }
    cout << lecture[i] << " ";
  }
  return 0;
}
