#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false), cin.tie(NULL);
  int n, m;
  cin >> n >> m;
  vector<string> v1(m);
  vector<string> v2(m);
  for (int i = 0; i < m; ++i) {
    cin >> v1[i] >> v2[i];
  }
  std::vector<string> v(n);
  for (auto &it : v) cin >> it;
  for (string i : v) {
    auto ff = find(v1.begin(), v1.end(), i);
    int f = distance(v1.begin(), ff);
    int s1 = v1[f].size(), s2 = v2[f].size();
    if (s1 <= s2)
      cout << v1[f] << " ";
    else
      cout << v2[f] << " ";
  }
  return 0;
}
