#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m1;
  cin >> n >> m1;
  map<string, string> m;
  while (m1--) {
    string s1, s2;
    cin >> s1 >> s2;
    m.insert(pair<string, string>(s1, s2));
  }
  while (n--) {
    string s;
    cin >> s;
    cout << ((s.length() <= m[s].length()) ? s : m[s]) << " ";
  }
}
