#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, i, j;
  cin >> n >> m;
  string s, ans;
  vector<pair<string, string>> p(m);
  for (i = 0; i < m; i++) cin >> p[i].first >> p[i].second;
  for (i = 0; i < n; i++) {
    cin >> s;
    for (j = 0; j < m; j++) {
      if (s == p[j].first || s == p[j].second) {
        if (p[j].second.length() < p[j].first.length())
          ans += p[j].second;
        else
          ans += p[j].first;
        ans += ' ';
      }
    }
  }
  cout << ans << endl;
  return 0;
}
