#include <bits/stdc++.h>
using namespace std;
int main() {
  int n1, n2;
  cin >> n1 >> n2;
  string* firstLang = new string[n2];
  string* secondLang = new string[n2];
  string* shorterWords = new string[n2];
  for (int i = 0; i < n2; i++) {
    cin >> firstLang[i];
    cin >> secondLang[i];
    if (secondLang[i].size() < firstLang[i].size()) {
      shorterWords[i] = secondLang[i];
    } else {
      shorterWords[i] = firstLang[i];
    }
  }
  string* toBeTranslated = new string[n1];
  string* Translated = new string[n1];
  for (int i = 0; i < n1; i++) {
    cin >> toBeTranslated[i];
    for (int j = 0; j < n2; j++) {
      if (toBeTranslated[i] == firstLang[j]) {
        Translated[i] = shorterWords[j];
        break;
      }
    }
  }
  for (int i = 0; i < n1; i++) {
    cout << Translated[i] << " ";
  }
}
