#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  map<string, string> mp;
  string a, b;
  while (m--) {
    cin >> a >> b;
    if (a.size() <= b.size())
      mp[a] = a;
    else
      mp[a] = b;
  }
  a.clear();
  b.clear();
  while (n--) {
    cin >> a;
    cout << mp[a] << ' ';
  }
  return 0;
}
