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