#include <bits/stdc++.h>
using namespace std;
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long int n, m;
  cin >> n >> m;
  vector<pair<string, string> > fin;
  for (long long int i = 0; i < m; i++) {
    string first;
    cin >> first;
    string second;
    cin >> second;
    if (first.length() <= second.length())
      fin.push_back(make_pair(first, first));
    else
      fin.push_back(make_pair(first, second));
  }
  vector<string> kal;
  for (long long int i = 0; i < n; i++) {
    string kal;
    cin >> kal;
    for (auto it : fin) {
      if (it.first == kal) {
        cout << it.second << " ";
      }
    }
  }
  return 0;
}
