#include <bits/stdc++.h>
using namespace std;
int main() {
  cin.tie(NULL);
  ios::sync_with_stdio(false);
  map<string, string> V;
  long long int n, m, i;
  cin >> n >> m;
  string str[n], s, s1;
  for (i = 0; i < m; i++) {
    cin >> s >> s1;
    V[s] = s1;
  }
  for (i = 0; i < n; i++) cin >> str[i];
  for (i = 0; i < n; i++) {
    if (V[str[i]].length() < str[i].length())
      cout << V[str[i]] << " ";
    else
      cout << str[i] << " ";
  }
  cout << endl;
  return 0;
}
