#include <bits/stdc++.h>
using namespace std;
int n, m;
map<string, string> mymap;
string s, c;
int main() {
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    cin >> s >> c;
    mymap[s] = c;
  }
  for (int i = 0; i < n; i++) {
    cin >> s;
    if (mymap[s].size() < s.size()) {
      cout << mymap[s] << ' ';
    } else
      cout << s << ' ';
  }
  cout << '\n';
}
