#include <bits/stdc++.h>
using namespace std;
void solve() {
  int n, m1, l1, l2;
  map<string, string> m;
  string s, s1, s2;
  vector<string> v;
  cin >> n >> m1;
  for (int i = 0; i < m1; i++) {
    cin >> s1 >> s2;
    int l1, l2;
    l1 = s1.length();
    l2 = s2.length();
    if (l1 < l2) {
      m[s1] = s1;
      m[s2] = s1;
    } else if (l2 < l1) {
      m[s2] = s2;
      m[s1] = s2;
    } else {
      m[s1] = s1;
      m[s2] = s2;
    }
  }
  for (int i = 0; i < n; i++) {
    cin >> s;
    v.push_back(m[s]);
  }
  for (int j = 0; j < v.size(); j++) {
    cout << v[j] << " ";
  }
  cout << endl;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  { solve(); }
  return 0;
}
