#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  scanf("%d %d", &n, &m);
  unordered_map<string, string> d;
  for (int i = 0; i < m; i++) {
    string x, y;
    cin >> x >> y;
    if ((int)x.size() > (int)y.size()) swap(x, y);
    d[y] = d[x] = x;
  }
  for (int i = 0; i < n; i++) {
    string x;
    cin >> x;
    cout << d[x] << " ";
  }
  return 0;
}
