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