#include <bits/stdc++.h>
using namespace std;
int main(void) {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int n, m, i, j;
  cin >> n >> m;
  string s[n + 5], a[m + 5], b[m + 5];
  for (i = 1; i <= m; ++i) cin >> a[i] >> b[i];
  for (i = 1; i <= n; ++i) cin >> s[i];
  for (i = 1; i <= n; ++i)
    for (j = 1; j <= m; ++j)
      if (s[i] == a[j]) {
        (a[j].size() <= b[j].size()) ? cout << a[j] << " "
                                     : cout << b[j] << " ";
        break;
      }
  return 0;
}
