#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  string a[m];
  string b[m];
  int al[3000];
  int bl[3000];
  string c[n];
  for (int i = 0; i < m; i++) {
    cin >> a[i] >> b[i];
    al[i] = a[i].length();
    bl[i] = b[i].length();
  }
  for (int i = 0; i < n; i++) {
    cin >> c[i];
    int j = 0;
    while (al[j] <= bl[j] || bl[j] < al[j]) {
      if (c[i] == a[j] || c[i] == b[j]) {
        if (al[j] <= bl[j]) {
          cout << a[j];
        } else
          cout << b[j];
        break;
      }
      j++;
    }
    if (i != n - 1) cout << ' ';
  }
  return 0;
}
