#include <bits/stdc++.h>
using namespace std;
const int maxn = 3005;
map<string, string> ma;
int main() {
  std::ios::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  int i;
  for (i = 0; i < m; ++i) {
    string s1, s2;
    cin >> s1 >> s2;
    if (s1.size() <= s2.size()) {
      ma.insert(make_pair(s1, s1));
      ma.insert(make_pair(s2, s1));
    } else {
      ma.insert(make_pair(s1, s2));
      ma.insert(make_pair(s2, s2));
    }
  }
  for (i = 0; i < n; ++i) {
    string t;
    cin >> t;
    cout << ma[t] << " ";
  }
  return 0;
}
