#include <bits/stdc++.h>
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
long long lstbt(long long val) {
  long long msk = val & (val - 1);
  return log2(val ^ msk);
}
void c_p_c() {}
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  c_p_c();
  long long n, m;
  cin >> n >> m;
  std::vector<pair<string, string>> v;
  for (long long i = 0; i < m; ++i) {
    string s, s1;
    cin >> s >> s1;
    v.push_back({s, s1});
  }
  for (long long i = 0; i < n; ++i) {
    string s;
    cin >> s;
    for (auto x : v) {
      if (x.first == s) {
        if (s.length() <= x.second.length()) {
          cout << s << " ";
        } else {
          cout << x.second << " ";
        }
      } else if (x.second == s) {
        if (s.length() <= x.first.length()) {
          cout << s << " ";
        } else {
          cout << x.first << " ";
        }
      }
    }
  }
}
