#include <bits/stdc++.h>
using namespace std;
int main() {
  map<string, string> mp;
  int n, m;
  string s1, s2;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    cin >> s1 >> s2;
    if (s1.size() > s2.size()) {
      mp[s1] = s2;
    } else
      mp[s1] = s1;
  }
  for (int i = 0; i < n; i++) {
    cin >> s1;
    cout << mp[s1] << " ";
  }
}
