#include <bits/stdc++.h>
using namespace std;
long long int o = 0, m;
long long int gcd(long long int a, long long int d) {
  if (d == 0)
    return a;
  else
    return gcd(d, a % d);
}
long long fade(long long x, long long p, long long m) {
  if (p == 1) return x;
  if (p % 2 == 0)
    return fade(((x % m) * (x % m)), p / 2, m) % m;
  else
    return ((fade((x % m) * (x % m), p / 2, m)) % m) * (x % m) % m;
}
int main() {
  string c, c1, m1;
  vector<pair<string, int>> k;
  int a, b;
  cin >> a >> b;
  for (int e = 0; e < b; ++e) {
    cin >> c >> c1;
    k.push_back(make_pair(c, c.size()));
    k.push_back(make_pair(c1, c1.size()));
  }
  for (int w = 0; w < a; ++w) {
    cin >> m1;
    for (int z = 0; z < k.size(); ++z) {
      if (k[z].first == m1) {
        if (k[z + 1].second < k[z].second) {
          cout << k[z + 1].first << " ";
          break;
        } else {
          cout << k[z].first << " ";
          break;
        }
      }
    }
  }
}
