#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  map<string, string> mp;
  string s1, s2, s[n];
  for (int i = 0; i < m; i++) {
    cin >> s1 >> s2;
    mp.insert(pair<string, string>(s1, s2));
  }
  for (int i = 0; i < n; i++) {
    cin >> s[i];
  }
  for (int i = 0; i < n; i++) {
    for (auto it = mp.begin(); it != mp.end(); it++) {
      if (s[i] == it->first) {
        if (s[i].size() > (it->second).size()) {
          cout << it->second << " ";
        } else {
          cout << s[i] << " ";
        }
      }
    }
  }
  cout << endl;
}
