#include <bits/stdc++.h>
using namespace std;
void solve() {
  long int n;
  cin >> n;
  long int m;
  cin >> m;
  map<string, string> first;
  while (m--) {
    string a, b;
    cin >> a >> b;
    first[a] = b;
  }
  while (n--) {
    string s;
    cin >> s;
    string s1 = first[s];
    if (s.length() > s1.length())
      cout << s1 << " ";
    else
      cout << s << " ";
  }
}
int main() {
  solve();
  return 0;
}
