#include <bits/stdc++.h>
using namespace std;
int main() {
  int sizeLect, sizeDict;
  scanf("%d %d", &sizeLect, &sizeDict);
  map<string, string> myDict;
  string w1, w2;
  for (int i = 0; i < (int)(sizeDict); ++i) {
    cin >> w1 >> w2;
    myDict[w1] = w2;
  }
  string profWord;
  string ans = "";
  string a, b;
  int counter = 0;
  while (cin >> profWord) {
    if (counter > 0) ans += " ";
    a = myDict.find(profWord)->first;
    b = myDict.find(profWord)->second;
    (a.size() <= b.size()) ? ans += a : ans += b;
    counter++;
  }
  cout << ans << endl;
  return 0;
}
