#include <bits/stdc++.h>
using namespace std;
void CIN() {
  cin.tie(0);
  ios_base::sync_with_stdio(0);
}
int revers(int x) {
  int rev = 0;
  while (x != 0) {
    int rem = x % 10;
    rev = rev * 10 + rem;
    x /= 10;
  }
  return rev;
}
long long GCD(long long u, long long v) {
  while (v != 0) {
    long long r = u % v;
    u = v;
    v = r;
  }
  return u;
}
string binary(long long x, long long siz) {
  string s;
  int counter = 0;
  while (x != 0 || counter < siz) {
    if (x % 2 == 0) {
      s += '0';
    } else {
      s += '1';
    }
    x /= 2;
    counter++;
  }
  return s;
}
int main() {
  CIN();
  long long h, k, o = 0, s = 1, n;
  long long a = 0;
  pair<string, string> arr[6000];
  string outer[10000];
  string u, l;
  cin >> a >> k;
  for (int i = 0; i < k; i++) {
    cin >> u >> l;
    if (u.size() == l.size()) {
      arr[i].second = u;
      arr[i].first = l;
    } else if (u.size() > l.size()) {
      arr[i].second = l;
      arr[i].first = u;
    } else {
      arr[i].second = u;
      arr[i].first = l;
    }
  }
  string q;
  for (int i = 0; i < a; i++) {
    cin >> q;
    bool flag = 0;
    for (int j = 0; j < k; j++) {
      if (q == arr[j].first) {
        outer[i] = arr[j].second;
        flag = 1;
        break;
      }
    }
    if (flag == 0) {
      outer[i] = q;
    }
  }
  for (int i = 0; i < a; i++) {
    cout << outer[i] << " ";
  }
  return 0;
}
