#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  string arr[3001][2];
  int choose[3001];
  for (int i = 0; i < m; i++) {
    cin >> arr[i][0] >> arr[i][1];
    if (arr[i][0].length() <= arr[i][1].length())
      choose[i] = 0;
    else
      choose[i] = 1;
  }
  string word;
  string result;
  for (int i = 0; i < n; i++) {
    cin >> word;
    for (int k = 0; k < m; k++) {
      if (word == arr[k][0]) result += arr[k][choose[k]] + " ";
    }
  }
  cout << result;
  return 0;
}
