#include <bits/stdc++.h>
using namespace std;
map<string, string> first, second;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n, m;
  cin >> n >> m;
  cin.ignore();
  for (int i = 1; i <= m; i++) {
    string s;
    getline(cin, s);
    int sz = s.size();
    string nn = "";
    for (int i = 0; i < sz; i++) {
      if (i == sz - 1 || s[i] == ' ') {
        if (i == sz - 1) {
          nn += s[i];
          second[nn] = s;
          nn = "";
        } else {
          first[nn] = s;
          nn = "";
        }
      } else
        nn += s[i];
    }
  }
  string s;
  getline(cin, s);
  int sz = s.size();
  vector<string> v;
  string nn = "";
  for (int i = 0; i < sz; i++) {
    if (i == sz - 1) {
      nn += s[i];
      v.push_back(nn);
    }
    if (s[i] == ' ') {
      v.push_back(nn);
      nn = "";
    } else
      nn += s[i];
  }
  for (int i = 0; i < n; i++) {
    string mm = "", s1 = "", s2 = "", s3 = "";
    if (first.count(v[i]))
      mm = first[v[i]];
    else
      mm = second[v[i]];
    int siz = mm.size();
    for (int j = 0; j < siz; j++) {
      if (mm[j] == ' ') {
        s1 = s3;
        s3 = "";
      } else
        s3 += mm[j];
      if (j == siz - 1) {
        s2 = s3;
      }
    }
    if (s1.size() <= s2.size())
      cout << s1 << " ";
    else
      cout << s2 << " ";
  }
  return 0;
}
