#include <bits/stdc++.h>
int main() {
  int n, m;
  char a[3001][11], b[3001][11];
  while (scanf("%d%d", &n, &m) != EOF) {
    int i, j, k = 1;
    char s[3001][11];
    for (i = 0; i < m; i++) scanf("%s%s", a[i], b[i]);
    for (i = 0; i < n; i++) scanf("%s", s[i]);
    for (i = 0; i < n; i++) {
      for (j = 0; j < m; j++) {
        if (strcmp(a[j], s[i]) == 0 || strcmp(b[j], s[i]) == 0) {
          k == 1 ? 0 : printf(" ");
          k == 1 ? k = 0 : 0;
          strlen(b[j]) < strlen(a[j]) ? printf("%s", b[j]) : printf("%s", a[j]);
        }
      }
    }
    printf("\n");
  }
}
