#include <bits/stdc++.h>
using namespace std;
class strocks {
 public:
  string strocksguy() {}
};
int main() {
  strocks strocks;
  iostream::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long n, m;
  cin >> n >> m;
  string s, d;
  unordered_map<string, string> master;
  for (long long i = 0; i < m; i++) {
    cin >> s >> d;
    if (s.size() > d.size()) {
      master.insert(make_pair(s, d));
    } else
      master.insert(make_pair(d, s));
  }
  for (long long i = 0; i < n; i++) {
    cin >> s;
    if (master.find(s) != master.end())
      cout << master.at(s) << ' ';
    else
      cout << s << ' ';
  }
  return 0;
}
