#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n, m;
  cin >> n >> m;
  map<string, string> mp;
  for (int i = 0; i < m; i++) {
    string s1, s2;
    cin >> s1 >> s2;
    if (s2.size() < s1.size())
      mp[s1] = s2;
    else
      mp[s1] = s1;
  }
  for (int i = 0; i < n; i++) {
    string s;
    cin >> s;
    for (auto it = mp.begin(); it != mp.end(); it++) {
      if (it->first == s) {
        cout << it->second << " ";
        break;
      }
    }
  }
  cout << '\n';
  return 0;
}
