#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m1;
  cin >> n >> m1;
  map<string, string> m;
  for (int i = 0; i < m1; i++) {
    string x, y;
    cin >> x >> y;
    m[x] = y;
  }
  for (int i = 0; i < n; i++) {
    string x;
    cin >> x;
    if (x.length() <= m[x].length()) {
      cout << x << " ";
    } else {
      cout << m[x] << " ";
    }
  }
  return 0;
}
