#include <bits/stdc++.h>
using namespace std;
int gray = 1, white = 0, black = 2;
int n, m, i, j;
char a[100][100];
map<pair<int, int>, vector<pair<int, int> > > mp;
vector<string> vv;
map<string, string> mm;
bool is_cycle(int id, int id1, map<pair<int, int>, int> color, int num) {
  color[{id, id1}] = gray;
  num++;
  for (int q = 0; q < mp[{id, id1}].size(); q++) {
    int x = mp[{id, id1}][q].first;
    int y = mp[{id, id1}][q].second;
    if (color[{x, y}] == gray && num > 4) return true;
    if (color[{x, y}] == white && is_cycle(x, y, color, num) && num > 4)
      return true;
  }
  color[{id, id1}] = black;
  return false;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin >> n >> m;
  for (i = 0; i < m; i++) {
    string a, b;
    cin >> a >> b;
    if (a.length() <= b.length()) {
      mm[a] = a;
      mm[b] = a;
    } else {
      mm[b] = b;
      mm[a] = b;
    }
  }
  for (i = 0; i < n; i++) {
    string s;
    cin >> s;
    vv.push_back(s);
  }
  for (i = 0; i < n; i++) cout << mm[vv[i]] << ' ';
  return 0;
}
