#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  string a[m];
  string b[m];
  for (long long i = 0; i < m; i++) {
    cin >> a[i] >> b[i];
  }
  string c[n];
  for (long long i = 0; i < n; i++) {
    cin >> c[i];
  }
  int k = 0;
  int i = 0;
  for (long long i = 0; i < n; i++) {
    for (long long k = 0; k < m; k++) {
      if (c[i] == a[k]) {
        if (a[k].length() <= b[k].length()) {
          cout << a[k] << ' ';
        } else {
          cout << b[k] << ' ';
        }
        i;
      }
    }
  }
  return 0;
}
