#include <bits/stdc++.h>
long long int MOD = 1000000007;
using namespace std;
long long int power(long long int x, long long int y, long long int p) {
  long long int res = 1;
  x = x % p;
  if (x == 0) return 0;
  while (y > 0) {
    if (y & 1) res = (res * x) % p;
    y = y >> 1;
    x = (x * x) % p;
  }
  return res;
}
bool sortbysec(const pair<long long int, long long int> &a,
               const pair<long long int, long long int> &b) {
  return (a.second < b.second);
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  ;
  long long int t;
  t = 1;
  while (t--) {
    long long int n, m;
    cin >> n >> m;
    string x;
    vector<string> b;
    vector<pair<string, string>> a(m);
    vector<pair<string, string>>::iterator it;
    for (long long int i = 0; i < m; i++) {
      cin >> a[i].first >> a[i].second;
    }
    for (long long int i = 0; i < n; i++) {
      cin >> x;
      it = std::find_if(
          a.begin(), a.end(),
          [&](pair<string, string> const &ref) { return ref.first == x; });
      string y = (x.size() <= (*it).second.size() ? x : (*it).second);
      b.push_back(y);
      b.push_back(" ");
    }
    for (auto &x : b) {
      cout << x;
    }
    return 0;
  }
}
