#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int n, m;
  cin >> n >> m;
  map<string, string> mp;
  while (m--) {
    string x, y;
    cin >> x >> y;
    if (x.size() <= y.size()) {
      mp[y] = x;
      mp[x] = x;
    } else {
      mp[x] = y;
      mp[y] = y;
    }
  }
  while (n--) {
    string a;
    cin >> a;
    cout << mp[a] << " ";
  }
  return 0;
}
