#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n, m;
  cin >> n >> m;
  unordered_map<string, string> words;
  while (m--) {
    string a, b;
    cin >> a >> b;
    words[a] = (b.length() < a.length()) ? b : a;
  }
  while (n--) {
    string w;
    cin >> w;
    auto const& f = words.find(w);
    if (f != words.end()) cout << f->second << " \n"[n == 0];
  }
  cout.flush();
}
