#include <bits/stdc++.h>
using namespace std;
template <class T>
void chmax(T &a, const T &b) {
  a = max(a, b);
}
template <class T>
void chmin(T &a, const T &b) {
  a = min(a, b);
}
int tmp;
void mswap(string &s1, string &s2) {
  if ((int)(s2.size()) < (int)(s1.size())) swap(s2, s1);
}
void solve() {
  int n, m;
  cin >> n >> m >> ws;
  vector<pair<string, string>> v(m);
  for (int i = 0; i < m; i++) {
    cin >> v[i].first >> v[i].second >> ws;
    mswap(v[i].first, v[i].second);
  }
  string q;
  for (int i = 0; i < n; i++) {
    cin >> q;
    for (auto it = v.begin(); it != v.end(); it++) {
      if (it->first == q or it->second == q) cout << it->first << " ";
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t = 1;
  while (t--) {
    solve();
  }
  cerr << "time taken : " << (float)clock() / CLOCKS_PER_SEC << " secs" << endl;
  return 0;
}
