#include <bits/stdc++.h>
using namespace std;
string sorting(string a, string b) {
  if (a.length() <= b.length()) return a;
  return b;
}
string word1[3010], word2[3010], words[3010];
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < m; i++) cin >> word1[i] >> word2[i];
  for (int i = 0; i < m; i++) words[i] = sorting(word1[i], word2[i]);
  for (int i = 0; i < n; i++) {
    string word;
    cin >> word;
    for (int i = 0; i < m; i++)
      if (word == word1[i] || word == word2[i]) cout << words[i] << ' ';
  }
}
