#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  string arr1[m], arr2[m];
  for (int i = 0; i < m; i++) {
    cin >> arr1[i];
    cin >> arr2[i];
  }
  string arr[n];
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (arr[i] == arr1[j] || arr[i] == arr2[j]) {
        if (arr1[j].length() <= arr2[j].length()) {
          cout << arr1[j] << " ";
        } else {
          cout << arr2[j] << " ";
        }
        break;
      }
    }
  }
}
