#include <bits/stdc++.h>
const int MAXN = (int)1e6 + 5;
const int MODN = (int)1e9 + 7;
const int N = 12;
int inf = 0x3f3f3f3f;
using namespace std;
map<char *, char *> mp;
map<char *, char *>::iterator it;
int main() {
  int n, m;
  char *s, *t;
  while (scanf("%d%d", &n, &m) != EOF) {
    for (int i = 0; i < m; i++) {
      s = new char[N];
      scanf("%s", s);
      t = new char[N];
      scanf("%s", t);
      mp[s] = t;
    }
    for (int i = 0; i < n; i++) {
      s = new char[N];
      scanf("%s", s);
      int l1 = strlen(s);
      for (it = mp.begin(); it != mp.end(); it++) {
        if (!strcmp(s, it->first)) {
          break;
        }
      }
      t = it->second;
      int l2 = strlen(t);
      if (l1 > l2) {
        printf("%s", t);
      } else {
        printf("%s", s);
      }
      if (i == n - 1) {
        printf("\n");
      } else {
        printf(" ");
      }
    }
  }
}
