#include <bits/stdc++.h>
int main() {
  int n, m, i, j, h = 0, k = 0, f1, l1, f2, l2, flag;
  scanf("%d %d", &n, &m);
  char arr1[22], arr2[m * 10], arr3[m * 10], arr4[n * 11];
  gets(arr1);
  for (i = 1; i <= m; i++) {
    gets(arr1);
    f1 = 0;
    for (j = 0; arr1[j] != ' '; j++) {
      l1 = j;
    }
    f2 = j + 1;
    for (j = f2; arr1[j] != '\0'; j++) {
      l2 = j;
    }
    if (l1 - f1 > l2 - f2) {
      for (j = f2; j <= l2; j++) {
        arr2[h] = arr1[j];
        h++;
      }
    } else {
      for (j = 0; j <= l1; j++) {
        arr2[h] = arr1[j];
        h++;
      }
    }
    for (h; h < i * 10; h++) {
      arr2[h] = ' ';
    }
    for (j = 0; j <= l1; j++) {
      arr3[k] = arr1[j];
      k++;
    }
    for (k; k < i * 10; k++) {
      arr3[k] = ' ';
    }
  }
  i = 0, j = 0, h = 0, k = 0;
  int index = 0, l;
  gets(arr4);
  for (h = 0; h < n; h++) {
    flag = 1;
    for (k = 0; k < m; k++) {
      flag = 1;
      j = k * 10;
      i = index;
      index = i;
      for (i; (arr4[i] != ' ' && arr4[i] != '\0'); i++) {
        if (arr4[i] != arr3[j]) {
          flag = 0;
          break;
        }
        j++;
      }
      if (flag == 1) {
        if (j % 10 == 0 || arr3[j] == ' ') {
          for (l = k * 10; (arr2[l] != ' ' && l < (k + 1) * 10); l++) {
            printf("%c", arr2[l]);
          }
          break;
        }
      }
    }
    if (h < n - 1) {
      printf(" ");
    }
    i++;
    index = i;
  }
  return 0;
}
