#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, i, j, m, x, y;
  vector<string> ss;
  vector<string> ss1;
  vector<string> ss2;
  string a, b;
  cin >> m >> n;
  for (i = 0; i < n; i++) {
    cin >> a >> b;
    ss.push_back(a);
    ss1.push_back(b);
  }
  for (i = 0; i < m; i++) {
    cin >> a;
    ss2.push_back(a);
  }
  for (i = 0; i < ss2.size(); i++) {
    a = ss2[i];
    for (j = 0; j < ss.size(); j++) {
      if ((ss[j] == a) || (ss1[j] == a)) {
        x = ss[j].size();
        y = ss1[j].size();
        if (x > y) {
          cout << ss1[j] << " ";
        } else if (x < y) {
          cout << ss[j] << " ";
        } else {
          cout << ss[j] << " ";
        }
        break;
      }
    }
  }
}
