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