#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  string *s1 = new string[m];
  string *s2 = new string[m];
  for (int i = 0; i < m; i++) cin >> s1[i] >> s2[i];
  string *k = new string[n];
  for (int i = 0; i < n; i++) cin >> k[i];
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++)
      if (k[i] == s1[j] || k[i] == s2[j]) {
        if (s1[j].length() < s2[j].length())
          k[i] = s1[j];
        else if (s1[j].length() > s2[j].length())
          k[i] = s2[j];
        else
          k[i] = s1[j];
        break;
      }
  for (int i = 0; i < n; i++) cout << k[i] << " ";
  cout << endl;
  return 0;
}
