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