#include <bits/stdc++.h>
using namespace std;
vector<pair<string, string> > data;
int main() {
  int n, m;
  string l1, l2;
  scanf("%d %d", &n, &m);
  for (int i = 0; i < m; i++) {
    cin >> l1 >> l2;
    data.push_back(make_pair(l1, l2));
  }
  for (int i = 0; i < n; i++) {
    cin >> l1;
    for (int j = 0; j < m; j++) {
      if (data[j].first == l1) {
        if (data[j].first.length() <= data[j].second.length())
          cout << data[j].first << " ";
        else
          cout << data[j].second << " ";
        break;
      }
    }
  }
  cout << endl;
  return 0;
}
