#include <bits/stdc++.h>
using namespace std;
int main() {
  int i, j, n, m;
  cin >> n >> m;
  string str[3100][2], strn[3100];
  for (i = 0; i < m; i++) {
    for (j = 0; j < 2; j++) cin >> str[i][j];
  }
  for (i = 0; i < n; i++) cin >> strn[i];
  for (i = 0; i < n; i++) {
    for (j = 0; j < m; j++) {
      if (strn[i] == str[j][0] || strn[i] == str[j][1]) {
        int l1 = str[j][0].length();
        int l2 = str[j][1].length();
        if (l1 <= l2)
          strn[i] = str[j][0];
        else
          strn[i] = str[j][1];
        cout << strn[i] << " ";
        break;
      }
    }
  }
  cout << endl;
  return 0;
}
