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