#include <bits/stdc++.h>
using namespace std;
map<string, string> m;
int main() {
  int m1, n;
  cin >> n >> m1;
  while (m1--) {
    string s, ss;
    cin >> s >> ss;
    m[s] = ss;
  }
  while (n--) {
    string s;
    cin >> s;
    string ss = m[s];
    if (s.size() <= ss.size())
      cout << s << " ";
    else
      cout << ss << " ";
  }
  return 0;
}
