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