#include <bits/stdc++.h>
using namespace std;
int bs(vector<string>& a, string x) {
  for (int i = 0; i < a.size(); i++)
    if (a[i] == x) return i;
  return -1;
}
int main() {
  int n, m;
  cin >> n >> m;
  vector<string> l1(m), l2(m);
  for (int i = 0; i < m; i++) {
    cin >> l1[i] >> l2[i];
  }
  vector<string> p(n);
  for (int i = 0; i < n; i++) {
    string t;
    cin >> t;
    int j = bs(l1, t);
    if (j == -1) j = bs(l2, t);
    p[i] = (l1[j].length() <= l2[j].length()) ? l1[j] : l2[j];
  }
  for (auto s : p) cout << s << " ";
  cout << endl;
  return 0;
}
