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