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