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