#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<string> v1(m), v2(m);
  string s;
  for (int i = 0; i < m; i++) {
    cin >> v1[i];
    cin >> v2[i];
  }
  for (int i = 0; i < n; i++) {
    cin >> s;
    int index;
    for (int j = 0; j < m; j++) {
      if (v1[j] == s) {
        index = j;
        break;
      }
    }
    v1[index].length() <= v2[index].length() ? cout << v1[index] << " "
                                             : cout << v2[index] << " ";
  }
  return 0;
}
