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