#include <bits/stdc++.h>
using namespace std;
int main() {
  unordered_map<string, string> m;
  vector<string> v;
  int n, mm;
  cin >> n >> mm;
  for (int i = 0; i < mm; i++) {
    string temp, name;
    cin >> temp >> name;
    m[temp] = name;
  }
  for (int i = 0; i < n; i++) {
    string name;
    cin >> name;
    v.push_back(name);
  }
  for (string i : v) {
    int length = i.size();
    int length2 = m[i].size();
    if (length <= length2) {
      cout << i << " ";
    } else {
      cout << m[i] << " ";
    }
  }
  return 0;
}
