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