#include <bits/stdc++.h>
using namespace std;
int m, n;
string sg, ai, bi;
string a[3000], b[3000];
void xly() {
  int y = 0;
  for (int i = 0; i < m; ++i) {
    if (sg == a[i]) {
      y = i;
      break;
    }
  }
  if (b[y].length() < a[y].length()) {
    cout << b[y];
  } else {
    cout << a[y];
  }
}
int main() {
  cin >> n >> m;
  for (int i = 0; i < m; ++i) {
    cin >> ai >> bi;
    a[i] = ai;
    b[i] = bi;
  }
  for (int i = 0; i < n; ++i) {
    cin >> sg;
    xly();
    if (i < n - 1) cout << " ";
  }
}
