#include <bits/stdc++.h>
using namespace std;
string a[1000000];
string b[1000000];
string c[1000000];
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= m; i++) {
    cin >> a[i] >> b[i];
  }
  for (int i = 1; i <= n; i++) {
    cin >> c[i];
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; 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] << " ";
      }
    }
  }
  return 0;
}
