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