#include <bits/stdc++.h>
int main() {
  char s1[3000][11], s2[3000][10], s3[3000][11];
  int m, n, i, j, k;
  int len1, len2;
  scanf("%d %d", &m, &n);
  for (i = 0; i < n; i++) {
    scanf("%s ", &s1[i]);
    gets(s2[i]);
  }
  for (i = 0; i < m - 1; i++) {
    scanf("%s ", &s3[i]);
  }
  gets(s3[m - 1]);
  for (i = 0; i < m; i++) {
    for (j = 0; j < n; j++) {
      if (strcmp(s3[i], s1[j]) == 0 || strcmp(s3[i], s2[j]) == 0) {
        len1 = strlen(s1[j]);
        len2 = strlen(s2[j]);
        if (len1 < len2) {
          k = 0;
          while (s1[j][k]) {
            printf("%c", s1[j][k]);
            k++;
          }
          printf(" ");
        } else if (len1 == len2) {
          k = 0;
          while (s1[j][k]) {
            printf("%c", s1[j][k]);
            k++;
          }
          printf(" ");
        } else {
          k = 0;
          while (s2[j][k]) {
            printf("%c", s2[j][k]);
            k++;
          }
          printf(" ");
        }
      }
    }
  }
  return 0;
}
