#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, i;
  map<string, string> mm;
  scanf("%d", &n);
  scanf("%d", &m);
  string a[m + 1], b[m + 1], s;
  for (i = 0; i < m; i++) {
    cin >> a[i] >> b[i];
    if (a[i].size() > b[i].size()) {
      mm[a[i]] = b[i];
    } else
      mm[a[i]] = a[i];
  }
  for (i = 0; i < n; i++) {
    cin >> s;
    cout << mm[s] << " ";
  }
  printf("\n");
  return 0;
}
