#include <bits/stdc++.h>
using namespace std;
const long long int mod = 1e9 + 7;
int main() {
  int n, m;
  cin >> n >> m;
  unordered_map<string, string> mp;
  while (m--) {
    string a, b;
    cin >> a >> b;
    mp[a] = b;
  }
  vector<string> s;
  vector<string> ans;
  string prof;
  while (n--) {
    cin >> prof;
    s.push_back(prof);
  }
  for (auto i : s) {
    if (mp.find(i) != mp.end()) {
      if (i.length() <= mp[i].length())
        ans.push_back(i);
      else
        ans.push_back(mp[i]);
    }
  }
  for (auto i : ans) {
    cout << i << " ";
  }
  cout << endl;
  return 0;
}
