#include <bits/stdc++.h>
#pragma warning(disable : 4996)
using namespace std;
int main() {
  string s1, s2, s;
  int n, m;
  scanf("%d%d", &n, &m);
  map<string, string> mp;
  for (int i = 0; i < m; ++i) {
    cin >> s1 >> s2;
    if (s2.size() >= s1.size())
      mp[s1] = s1;
    else
      mp[s1] = s2;
  }
  for (int i = 0; i < n; ++i) {
    cin >> s;
    cout << mp[s] << " ";
  }
  return 0;
}
