#include <bits/stdc++.h>
using namespace std;
int main() {
  map<string, string> ltl;
  int n, m;
  cin >> n >> m;
  string a, b;
  while (m--) {
    cin >> a >> b;
    ltl[a] = b;
  }
  while (n--) {
    cin >> a;
    if (a.size() > ltl[a].size()) a = ltl[a];
    cout << a << ' ';
  }
  return 0;
}
