#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  string words[m][2];
  for (int i = 0; i < m; i++) {
    cin >> words[i][0] >> words[i][1];
  }
  string s;
  vector<string> v;
  for (int i = 0; i < n; i++) {
    cin >> s;
    for (int j = 0; j < m; j++) {
      if (s == words[j][0] || s == words[j][1]) {
        int len1 = words[j][0].length();
        int len2 = words[j][1].length();
        if (len1 <= len2)
          v.push_back(words[j][0]);
        else if (len2 < len1)
          v.push_back(words[j][1]);
      }
    }
  }
  int len = v.size();
  for (int i = 0; i < len; i++) cout << v[i] << " ";
  cout << "\n";
  return 0;
}
