#include <bits/stdc++.h>
using namespace std;
struct q {
  char x[20];
  char y[20];
};
struct w {
  char z[20];
};
struct e {
  char c[20];
};
int main() {
  int n, m;
  cin >> n >> m;
  q q1[m];
  int i = 0, j = 0;
  for (i; i < m; i++) {
    cin >> q1[i].x;
    cin >> q1[i].y;
  }
  w w1[n];
  for (i = 0; i < n; i++) {
    cin >> w1[i].z;
  }
  e e1[n];
  for (i = 0; i < n; i++) {
    for (j = 0; j < m; j++) {
      if (strcmp(w1[i].z, q1[j].x) == 0) {
        if (strlen(q1[j].x) <= (strlen(q1[j].y)))
          strcpy(e1[i].c, q1[j].x);
        else
          strcpy(e1[i].c, q1[j].y);
      }
    }
  }
  for (i = 0; i < n; i++) {
    cout << e1[i].c;
    cout << " ";
  }
  return 0;
}
