#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  while (cin >> n >> m) {
    vector<pair<string, string>> words(m);
    vector<string> lecture(n);
    for (int i = 0; i < m; ++i) cin >> words.at(i).first >> words.at(i).second;
    for (int i = 0; i < n; ++i) cin >> lecture.at(i);
    for (int i = 0; i < n; ++i) {
      for (int j = 0; j < m; ++j) {
        if (lecture.at(i) == words.at(j).first ||
            lecture.at(i) == words.at(j).second)
          if (words.at(j).first.size() > words.at(j).second.size())
            lecture.at(i) = words.at(j).second;
          else if (words.at(j).first.size() < words.at(j).second.size())
            lecture.at(i) = words.at(j).first;
          else
            lecture.at(i) = words.at(j).first;
      }
    }
    for (int i = 0; i < n; ++i) {
      cout << lecture.at(i);
      if (i != n - 1) cout << ' ';
    }
    cout << endl;
  }
  return 0;
}
