#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<pair<string, string> > v;
  for (int i = 0; i < m; i++) {
    string s1, s2;
    cin >> s1 >> s2;
    v.push_back(make_pair(s1, s2));
  }
  for (int i = 0; i < n; i++) {
    string s;
    cin >> s;
    for (int j = 0; j < v.size(); j++) {
      if (s == v[j].first) {
        int l1 = v[j].first.length();
        int l2 = v[j].second.length();
        if (l2 < l1) {
          cout << v[j].second << " ";
        } else {
          cout << v[j].first << " ";
        }
        break;
      } else {
        continue;
      }
    }
  }
}
