#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int m;
  cin >> m;
  map<string, string> lang;
  queue<string> save;
  for (int i = 0, _a = (m); i < _a; i++) {
    string tg;
    cin >> tg;
    string _tg;
    cin >> _tg;
    if (tg.size() <= _tg.size())
      lang[tg] = tg;
    else
      lang[tg] = _tg;
  }
  for (int i = 0, _a = (n); i < _a; i++) {
    string tg;
    cin >> tg;
    save.push(tg);
  }
  for (int i = 0, _a = (n); i < _a; i++) {
    cout << lang[save.front()] << " ";
    save.pop();
  }
  return 0;
}
