#include <bits/stdc++.h>
using namespace std;
map<string, string> words;
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    string a, b;
    cin >> a >> b;
    words[a] = b;
  }
  for (int i = 0; i < n; i++) {
    string word;
    cin >> word;
    string b = words[word];
    if (word.length() <= b.length()) {
      cout << word;
    } else {
      cout << b;
    }
    if (i < n - 1) {
      cout << " ";
    }
  }
  cout << endl;
}
