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