#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<string> lect(n);
  string s;
  vector<string> lang1(m);
  vector<string> lang2(m);
  for (int i = 0; i < m; i++) {
    cin >> lang1[i];
    cin >> lang2[i];
  }
  string t;
  getline(cin, t);
  getline(cin, s);
  int j = 0;
  int pos = 0;
  string s1 = "";
  for (int i = 0; i < s.length(); i++) {
    if (s[i] == ' ') {
      if (pos == 0) {
        s1 = s.substr(pos, i - pos);
        lect[j] = s1;
        j++;
        pos = i;
      } else {
        s1 = s.substr(pos + 1, i - pos - 1);
        lect[j] = s1;
        j++;
        pos = i;
      }
    }
    if (i == s.length() - 1) {
      if (pos == 0) {
        s1 = s.substr(pos, i + 1);
        lect[j] = s1;
        j++;
        pos = i;
      } else {
        s1 = s.substr(pos + 1, i - pos);
        lect[j] = s1;
        j++;
        pos = i;
      }
    }
  }
  vector<string> ans(n);
  for (int i = 0; i < n; i++) {
    bool ok = false;
    for (int p = 0; p < m; p++) {
      if (lect[i] == lang1[p] && ok == false) {
        ok == true;
        if (lang1[p].size() < lang2[p].size()) {
          ans[i] = lang1[p];
        } else if (lang1[p].size() > lang2[p].size()) {
          ans[i] = lang2[p];
        } else if (lang1[p].size() == lang2[p].size()) {
          ans[i] = lang1[p];
        }
      }
    }
    if (ok == false) {
      for (int q = 0; q < m; q++) {
        if (lect[i] == lang2[q]) {
          if (lang2[q].size() < lang1[q].size()) {
            ans[i] = lang2[q];
          } else if (lang2[q].size() > lang1[q].size()) {
            ans[i] = lang1[q];
          } else if (lang2[q].size() == lang1[q].size()) {
            ans[i] = lang1[q];
          }
        }
      }
    }
  }
  for (int i = 0; i < n; i++) cout << ans[i] << ' ';
  return 0;
}
