#include <bits/stdc++.h>
using namespace std;
map<string, string> haha;
string lec[10000];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    string a, b;
    cin >> a >> b;
    haha[a] = b;
  }
  for (int i = 0; i < n; i++) {
    cin >> lec[i];
  }
  for (int i = 0; i < n; i++) {
    if (lec[i].size() <= haha[lec[i]].size()) {
      cout << lec[i] << " ";
    } else
      cout << haha[lec[i]] << " ";
  }
}
