#include <bits/stdc++.h>
using namespace std;
int main() {
  map<string, string> myMap;
  vector<string> myVector;
  string str1, str2;
  string compare;
  int n, t;
  cin >> n >> t;
  for (int i = 0; i < t; i++) {
    cin >> str1 >> str2;
    myMap[str1] = str2;
  }
  for (int j = 0; j < n; j++) {
    cin >> str1;
    myVector.push_back(str1);
  }
  string out = "";
  for (int h = 0; h < n; h++) {
    for (map<string, string>::iterator it = myMap.begin(); it != myMap.end();
         ++it) {
      if (it->first == myVector[h] || it->second == myVector[h]) {
        if (it->first.length() == it->second.length()) {
          out += myVector[h];
          break;
        } else if (it->first.length() < it->second.length()) {
          out += it->first;
          break;
        } else {
          out += it->second;
          break;
        }
      }
    }
    out += " ";
  }
  cout << out << endl;
}
