#include <bits/stdc++.h>
using namespace std;
int main() {
  map<string, string> memo;
  int a, b;
  cin >> a >> b;
  while (b > 0) {
    string input[2];
    for (int i = 0; i < 2; i++) {
      cin >> input[i];
    }
    memo.insert(pair<string, string>(input[0], input[1]));
    b--;
  }
  string first, second;
  string tmp;
  for (int i = 0; i < a; i++) {
    cin >> tmp;
    first = tmp;
    second = memo[tmp];
    if (tmp.length() <= second.length())
      cout << tmp;
    else
      cout << memo[tmp];
    if (i != a - 1) cout << " ";
  }
  cout << endl;
  return 0;
}
