#include <bits/stdc++.h>
using namespace std;
string a, b;
int n, m;
map<string, string> mp;
int main() {
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    cin >> a >> b;
    mp[a] = b;
  }
  for (int i = 0; i < n; i++) {
    cin >> a;
    if (a.size() == mp[a].size())
      cout << a << " ";
    else if (a.size() < mp[a].size())
      cout << a << " ";
    else
      cout << mp[a] << " ";
  }
}
