#include <bits/stdc++.h>
using namespace std;
bool isBelongToTheWordsRecord(string target, string leterOfLanguages) {
  int positionSpace = (int)leterOfLanguages.find(" ");
  string firstLanguage = leterOfLanguages.substr(0, positionSpace);
  string secondeLanguage =
      leterOfLanguages.substr(positionSpace + 1, leterOfLanguages.length() - 1);
  if (target.compare(firstLanguage) == 0 ||
      target.compare(secondeLanguage) == 0) {
    return true;
  }
  return false;
}
string getTheWordsRecordLecture(string leterOfLanguages) {
  int positionSpace = (int)leterOfLanguages.find(" ");
  string firstLanguage = leterOfLanguages.substr(0, positionSpace);
  string secondeLanguage =
      leterOfLanguages.substr(positionSpace + 1, leterOfLanguages.length() - 1);
  return (firstLanguage.length() <= secondeLanguage.length()) ? firstLanguage
                                                              : secondeLanguage;
}
int main(int argc, const char* argv[]) {
  int n;
  cin >> n;
  int m;
  cin >> m;
  string output = "";
  vector<string> inputNumbersOfWords;
  for (int i = 0; i < m + 1; i++) {
    string value;
    getline(cin, value);
    if (!value.empty()) {
      inputNumbersOfWords.push_back(value);
    }
  }
  string lecture;
  getline(cin, lecture);
  for (int i = 0; i < n; i++) {
    int positionSpace = (int)lecture.find(" ");
    string item = lecture.substr(0, positionSpace);
    lecture.replace(lecture.begin(), lecture.begin() + positionSpace + 1, "");
    for (int j = 0; j < inputNumbersOfWords.size(); j++) {
      if (inputNumbersOfWords[j].find(item) != -1 &&
          isBelongToTheWordsRecord(item, inputNumbersOfWords[j])) {
        output += getTheWordsRecordLecture(inputNumbersOfWords[j]) + " ";
        break;
      }
    }
  }
  cout << output << endl;
  return 0;
}
