#include <bits/stdc++.h>
using namespace std;
int main() {
  map<string, string> a, b;
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    string s, t;
    cin >> s >> t;
    a[s] = t;
    b[t] = s;
  }
  for (int i = 0; i < n; i++) {
    string s;
    cin >> s;
    if (a.find(s) != a.end()) {
      if (a[s].length() < s.length())
        cout << a[s] << " ";
      else
        cout << s << " ";
    } else {
      if (s.length() < b[s].length())
        cout << s << " ";
      else
        cout << b[s] << " ";
    }
  }
  cout << endl;
  return 0;
}
