#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
long long expo(long long x, long long y) {
  long long res = 1;
  while (y) {
    if (y % 2) res = (res * x % mod) % mod;
    x = (x * x) % mod;
    y /= 2;
  }
  return res;
}
long long inv(long long x) { return expo(x, mod - 2); }
long long add(long long x, long long y) { return (x + y) % mod; }
long long sub(long long x, long long y) { return (x - y) % mod; }
long long mul(long long x, long long y) {
  return ((x % mod) * (y % mod)) % mod;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long n, m;
  cin >> n >> m;
  map<string, string> ans;
  for (long long i = 0; i < m; i++) {
    string a, b;
    cin >> a >> b;
    if (b.length() < a.length())
      ans[a] = b;
    else
      ans[a] = a;
  }
  for (long long i = 0; i < n; i++) {
    string a;
    cin >> a;
    cout << ans[a] << " ";
  }
  cout << "\n";
}
