#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  string temp;
  getline(cin, temp);
  string words[m][2];
  string lec[n];
  string str;
  for (int i = 0; i < m; i++) {
    for (int j = 0; j < 2; j++) {
      cin >> words[i][j];
    }
  }
  for (int i = 0; i < n; i++) {
    cin >> lec[i];
  }
  for (int q = 0; q < n; q++) {
    for (int i = 0; i < m; i++) {
      for (int j = 0; j < 2; j++) {
        if (lec[q] == words[i][j]) {
          if (words[i][1].size() < words[i][0].size()) {
            cout << words[i][1] << " ";
          } else {
            cout << words[i][0] << " ";
          }
        }
      }
    }
  }
}
