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