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