#include <bits/stdc++.h>
using namespace std;
map<string, string> mp;
int main() {
  int n, m;
  string s, s1, s2;
  scanf("%d%d", &n, &m);
  for (int i = 0; i < m; i++) {
    cin >> s1 >> s2;
    mp[s1] = s2;
  }
  for (int i = 0; i < n; ++i) {
    cin >> s;
    s1 = (mp[s]);
    if (s1.length() < s.length())
      cout << s1 << " ";
    else
      cout << s << " ";
  }
  cout << "\n";
  return 0;
}
