#include <bits/stdc++.h>
using namespace std;
map<string, string> m;
int n, mm;
string s1, s2;
map<string, int> m2;
int main() {
  cin >> n >> mm;
  for (int i = 0; i < mm; ++i) {
    cin >> s1 >> s2;
    m[s1] = s2;
    m[s2] = s1;
    m2[s1] = 1;
    m2[s2] = 2;
  }
  for (int i = 0; i < n; ++i) {
    cin >> s1;
    int l1 = s1.size();
    int l2 = m[s1].size();
    if (l1 < l2)
      cout << s1 << " ";
    else if (l2 < l1)
      cout << m[s1] << " ";
    else {
      if (m2[s1] == 1)
        cout << s1 << " ";
      else
        cout << m[s1] << " ";
    }
  }
}
