#include <bits/stdc++.h>
using namespace std;
map<string, string> mp;
void solve() {
  long long n, m;
  cin >> n >> m;
  for (long long i = 0; i < m; i++) {
    string a, b;
    cin >> a >> b;
    mp[a] = b;
    mp[b] = a;
  }
  for (long long i = 0; i < n; i++) {
    string a;
    cin >> a;
    string ans, b = mp[a];
    if (b.length() < a.length()) {
      ans = b;
    } else
      ans = a;
    cout << ans << ' ';
  }
  cout << '\n';
}
int main() {
  solve();
  return 0;
}
