#include <bits/stdc++.h>
using namespace std;
unordered_map<string, string> dic;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n, m;
  string s1, s2, cad;
  cin >> m >> n;
  for (int i = 0; i < n; i++) {
    cin >> s1 >> s2;
    if (s2.size() < s1.size())
      dic[s1] = s2;
    else
      dic[s1] = s1;
  }
  for (int i = 0; i < m; i++) {
    cin >> cad;
    cout << dic[cad] << '\n';
  }
  return 0;
}
