#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  int n, m;
  cin >> n >> m;
  string s1, s2;
  map<string, string> m1, m2;
  for (int i = 0; i < m; i++) {
    cin >> s1 >> s2;
    m1[s1] = s2;
    m2[s2] = s1;
  }
  for (int i = 0; i < n; i++) {
    cin >> s1;
    if (m1[s1] != " ") {
      if (s1.size() <= m1[s1].size())
        cout << s1 << " ";
      else
        cout << m1[s1] << " ";
    } else {
      if (m2[s1].size() <= s1.size())
        cout << m2[s1] << " ";
      else
        cout << s1 << " ";
    }
  }
}
