#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, k = 0;
  cin >> n >> m;
  string s1[m][2], s2[n];
  int a1[m][2], a2[n];
  for (int x = 0; x < m; x++) {
    for (int y = 0; y < 2; y++) {
      cin >> s1[x][y];
      a1[x][y] = s1[x][y].length();
    }
  }
  for (int x = 0; x < n; x++) {
    cin >> s2[x];
    a2[x] = s2[x].length();
  }
  for (int x = 0; x < n; x++) {
    for (int y = 0; y < m; y++) {
      k = 0;
      for (int z = 0; z < s1[y][0].length(); z++) {
        if (s1[y][0].length() != s2[x].length()) {
          k = 1;
          break;
        } else if ((int)s1[y][0].at(z) != (int)s2[x].at(z)) {
          k = 1;
          break;
        }
      }
      if (k == 0) {
        if (a1[y][0] <= a1[y][1]) {
          cout << s1[y][0] << " ";
        } else {
          cout << s1[y][1] << " ";
        }
        break;
      }
    }
  }
}
