#include <bits/stdc++.h>
using namespace std;
int findIndex(string, string[][2], int);
int main(int argc, char const *argv[]) {
  int n, m, index;
  cin >> n >> m;
  string lecture[n];
  string words[m][2];
  for (int i = 0; i < m; ++i) cin >> words[i][0] >> words[i][1];
  for (int i = 0; i < n; ++i) {
    cin >> lecture[i];
    index = findIndex(lecture[i], words, m);
    if (words[index][0].length() <= words[index][1].length())
      cout << words[index][0] << " ";
    else
      cout << words[index][1] << " ";
  }
  return 0;
}
int findIndex(string proffesorWord, string words[][2], int wordsLength) {
  for (int i = 0; i < wordsLength; ++i) {
    if (proffesorWord == words[i][0]) return i;
  }
  return -1;
}
