#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  map<string, string> word;
  string w1, w2;
  for (int i = 0; i < m; i++) {
    cin >> w1 >> w2;
    if (w1.length() > w2.length())
      word.insert(pair<string, string>(w1, w2));
    else
      word.insert(pair<string, string>(w1, w1));
  }
  string speech[3001], temp;
  for (int i = 0; i < n; i++) {
    cin >> temp;
    if (word[temp] != "") {
      temp = word[temp];
    }
    speech[i] = temp;
  }
  for (int i = 0; i < n; i++) {
    cout << speech[i] << " ";
  }
  return 0;
}
