#include <bits/stdc++.h>
using namespace std;
int main() {
  cin.tie(NULL);
  ios_base::sync_with_stdio(false);
  long long n, m;
  cin >> n >> m;
  map<string, string> ma;
  for (long long i = 0; i < m; i++) {
    string s1, s2;
    cin >> s1 >> s2;
    if (s2.size() < s1.size())
      ma[s1] = s2;
    else
      ma[s1] = s1;
  }
  for (long long i = 0; i < n; i++) {
    string second;
    cin >> second;
    cout << ma[second] << " ";
  }
}
