#include <bits/stdc++.h>
using namespace std;
struct trp {
  int x, y, z;
};
void fun() {}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int n, m;
  cin >> n >> m;
  map<string, string> make_pair;
  while (m--) {
    string a, b;
    cin >> a >> b;
    if (a.length() > b.length()) {
      make_pair[a] = b;
      make_pair[b] = b;
    } else {
      make_pair[a] = a;
      make_pair[b] = a;
    }
  }
  while (n--) {
    string s;
    cin >> s;
    cout << make_pair[s] << " ";
  }
}
