#include <bits/stdc++.h>
using namespace std;
string s[3005];
map<string, string> p;
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= m; i++) {
    string x, y;
    cin >> x >> y;
    p[x] = y;
    p[y] = x;
  }
  for (int i = 1; i <= n; i++) {
    cin >> s[i];
    if (p[s[i]].length() < s[i].length()) {
      s[i] = p[s[i]];
    }
  }
  for (int i = 1; i <= n; i++) {
    cout << s[i] << " ";
  }
  cout << endl;
}
