#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  int n, m, i;
  string c, b;
  map<string, pair<string, string>> a;
  cin >> n >> m;
  for (i = 0; i < m; ++i) {
    cin >> c >> b;
    a[c] = {c, b};
  }
  for (i = 0; i < n; ++i) {
    cin >> c;
    if (c.length() > a[c].second.length())
      cout << a[c].second;
    else
      cout << c;
    cout << " ";
  }
  return 0;
}
