#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ;
  int n, m;
  cin >> n >> m;
  string a[3000], b[3000], c[3000], p[3000];
  for (int i = 0; i < m; i++) {
    cin >> a[i] >> b[i];
  }
  for (int i = 0; i < n; i++) {
    cin >> c[i];
    for (int j = 0; j < m; j++) {
      if (c[i] == a[j] || c[i] == b[j]) {
        if (a[j].size() <= b[j].size()) {
          cout << a[j] << " ";
        } else
          cout << b[j] << " ";
        break;
      }
    }
  }
  return 0;
}
