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