#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n, m;
  cin >> n >> m;
  unordered_map<string, string> words;
  for (int i = 0; i < m; i++) {
    string a, b;
    cin >> a >> b;
    words[a] = b;
  }
  vector<string> output(n);
  for (int i = 0; i < n; i++) {
    string s;
    cin >> s;
    output[i] = (s.size() <= words[s].size()) ? s : words[s];
  }
  for (int i = 0; i < n; i++) {
    cout << output[i] << " ";
  }
  return 0;
}
