#include <bits/stdc++.h>
using namespace std;
int n, m;
string s[3][3000], str;
bool flag = 1;
int main() {
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    cin >> s[0][i] >> s[1][i];
    if (s[0][i].size() <= s[1][i].size())
      s[2][i] = s[0][i];
    else
      s[2][i] = s[1][i];
  }
  for (int i = 0; i < n; i++) {
    cin >> str;
    flag = 1;
    for (int i = 0; i < m && flag; i++) {
      for (int j = 0; j < 2 && flag; j++)
        if (str == s[j][i]) {
          cout << s[2][i] << " ";
          flag = 0;
        }
    }
  }
}
