#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n, m;
  cin >> n >> m;
  string a[m], b[m];
  int i;
  for (i = 0; i < m; i++) {
    cin >> a[i] >> b[i];
  }
  string s[n];
  for (i = 0; i < n; i++) cin >> s[i];
  map<string, string> mp;
  for (i = 0; i < m; i++) mp[a[i]] = b[i];
  int k, l;
  string str;
  for (i = 0; i < n; i++) {
    k = s[i].length();
    str = mp[s[i]];
    l = str.length();
    if (k <= l)
      cout << s[i] << " ";
    else
      cout << str << " ";
  }
  return 0;
}
