#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  string* a = new string[m];
  string* b = new string[m];
  string* ans = new string[n];
  int p = 0;
  for (int i = 0; i < m; i++) {
    cin >> a[i] >> b[i];
  }
  for (int i = 0; i < n; i++) {
    string g;
    cin >> g;
    for (int j = 0; j < m; j++) {
      if (g == a[j]) {
        if (a[j].size() > b[j].size())
          ans[p++] = b[j];
        else
          ans[p++] = a[j];
      }
    }
  }
  for (int u = 0; u < p; u++) {
    cout << ans[u] << " ";
  }
  return 0;
}
