#include <bits/stdc++.h>
using namespace std;
int main() {
  int a{0}, b{0};
  cin >> a >> b;
  vector<pair<string, int>> vec1(b), vec2(b);
  for (int i = 0; i < b; i++) {
    cin >> vec1[i].first >> vec2[i].first;
    vec1[i].second = (vec1[i].first).length();
    vec2[i].second = (vec2[i].first).length();
  }
  while (a--) {
    string s;
    cin >> s;
    for (int i = 0; i < b; i++) {
      if (s == vec1[i].first) {
        if (vec1[i].second <= vec2[i].second) {
          cout << vec1[i].first << " ";
        } else {
          cout << vec2[i].first << " ";
        }
        break;
      }
    }
  }
  cout << endl;
  return 0;
}
