#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:16777216")
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  string a, b;
  map<string, string> dict;
  for (long long i = 0; i < (int)m; i++) {
    cin >> a >> b;
    dict[a] = b;
  }
  for (long long i = 0; i < (int)n; i++) {
    cin >> a;
    if (dict[a].length() < a.length()) {
      if (i == n - 1)
        cout << dict[a] << endl;
      else
        cout << dict[a] << " ";
    } else {
      if (i == n - 1)
        cout << a << endl;
      else
        cout << a << " ";
    }
  }
  return 0;
}
