#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  map<string, string> uses;
  string t1, t2;
  for (int i = 0; i < m; i++) {
    cin >> t1 >> t2;
    if (t2.length() < t1.length())
      uses[t1] = t2;
    else
      uses[t1] = t1;
  }
  string lec;
  for (int i = 0; i < n; i++) {
    cin >> lec;
    if (i != 0) cout << " ";
    cout << uses[lec];
  }
  cout << endl;
}
