#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  string s1, s2;
  map<string, string> lecture;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    cin >> s1 >> s2;
    lecture[s1] = s2;
  }
  for (int i = 0; i < n; i++) {
    cin >> s1;
    s2 = lecture[s1];
    if (s1.length() <= s2.length())
      cout << s1 << " ";
    else
      cout << s2 << " ";
  }
  cout << endl;
}
