#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
template <typename T>
vector<T>& operator--(vector<T>& v) {
  for (auto& i : v) --i;
  return v;
}
template <typename T>
vector<T>& operator++(vector<T>& v) {
  for (auto& i : v) ++i;
  return v;
}
template <typename T>
istream& operator>>(istream& is, vector<T>& v) {
  for (auto& i : v) is >> i;
  return is;
}
template <typename T>
ostream& operator<<(ostream& os, vector<T> v) {
  for (auto& i : v) os << i << ' ';
  return os;
}
template <typename T, typename U>
pair<T, U>& operator--(pair<T, U>& p) {
  --p.first;
  --p.second;
  return p;
}
template <typename T, typename U>
pair<T, U>& operator++(pair<T, U>& p) {
  ++p.first;
  ++p.second;
  return p;
}
template <typename T, typename U>
istream& operator>>(istream& is, pair<T, U>& p) {
  is >> p.first >> p.second;
  return is;
}
template <typename T, typename U>
ostream& operator<<(ostream& os, pair<T, U> p) {
  os << p.first << ' ' << p.second;
  return os;
}
template <typename T, typename U>
pair<T, U> operator-(pair<T, U> a, pair<T, U> b) {
  return make_pair(a.first - b.first, a.second - b.second);
}
template <typename T, typename U>
pair<T, U> operator+(pair<T, U> a, pair<T, U> b) {
  return make_pair(a.first + b.first, a.second + b.second);
}
template <typename T, typename U>
void umin(T& a, U b) {
  if (a > b) a = b;
}
template <typename T, typename U>
void umax(T& a, U b) {
  if (a < b) a = b;
}
struct Node {
  bool end = false;
  map<char, Node*> to;
};
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n;
  cin >> n;
  vector<string> res(n);
  cin >> res;
  set<string> ress(res.begin(), res.end());
  Node* root = new Node();
  for (string s : res) {
    auto node = root;
    for (char c : s) {
      if (!node->to.count(c)) node->to[c] = new Node();
      node = node->to[c];
    }
    node->end = true;
  }
  int m;
  cin >> m;
  vector<string> tokens0;
  {
    string s;
    getline(cin, s);
    for (int it = 0; it < m; ++it) {
      getline(cin, s);
      for (int i = 0; i < s.size(); ++i) {
        if (s[i] == '#') {
          s.resize(i);
          break;
        }
      }
      int last = 0;
      for (int i = 0; i <= s.size(); ++i) {
        if (i == s.size() || s[i] == ' ') {
          if (last != i) {
            tokens0.push_back(s.substr(last, i - last));
          }
          last = i + 1;
        }
      }
    }
  }
  void(0);
  vector<pair<string, int>> tokens;
  auto is_let = [&](char c) {
    if ('a' <= c && c <= 'z') return true;
    if ('A' <= c && c <= 'Z') return true;
    if ('0' <= c && c <= '9') return true;
    if (c == '$') return true;
    if (c == '_') return true;
    return false;
  };
  auto parse_tokens = [&](string s) {
    vector<pair<string, int>> tokens;
    int ind = 0;
    while (ind < s.size()) {
      int was = ind;
      auto node = root;
      int best_sz = 0;
      for (int i = ind; i < s.size(); ++i) {
        char c = s[i];
        if (!node->to.count(c)) break;
        node = node->to[c];
        if (node->end) best_sz = i + 1 - ind;
      }
      string best_res = s.substr(ind, best_sz);
      void(0);
      if ('0' <= s[ind] && s[ind] <= '9') {
        int it = ind;
        while (it < s.size() && s[it] >= '0' && s[it] <= '9') ++it;
        void(0);
        if (it - ind > best_res.size()) {
          tokens.emplace_back(s.substr(ind, it - ind), 1);
          ind = it;
        } else {
          tokens.emplace_back(best_res, 0);
          ind += best_res.size();
        }
      } else {
        int it = ind;
        while (it < s.size() && is_let(s[it])) ++it;
        void(0);
        if (it - ind > best_res.size()) {
          tokens.emplace_back(s.substr(ind, it - ind), 2);
          ind = it;
        } else {
          tokens.emplace_back(best_res, 0);
          ind += best_res.size();
        }
      }
      if (ind <= was) {
        return make_pair(tokens, false);
      }
    }
    return make_pair(tokens, true);
  };
  for (auto s : tokens0) {
    auto v = parse_tokens(s).first;
    for (auto p : v) tokens.push_back(p);
  }
  set<pair<int, string>> avail_names;
  for (int ln = 1; ln <= 3; ++ln) {
    int cnt = 1;
    for (int i = 0; i < ln; ++i) {
      cnt *= 26;
    }
    for (int i = 0; i < cnt; ++i) {
      string t;
      int x = i;
      for (int j = 0; j < ln; ++j) {
        t.push_back('a' + x % 26);
        x /= 26;
      }
      if (ress.count(t)) continue;
      avail_names.emplace(ln, t);
    }
  }
  map<string, string> names;
  for (auto& [s, tp] : tokens) {
    if (tp != 2) continue;
    if (!names.count(s)) {
      names[s] = avail_names.begin()->second;
      avail_names.erase(avail_names.begin());
    }
    s = names[s];
  }
  void(0);
  string curs;
  for (int i = 0; i < tokens.size(); ++i) {
    cout << tokens[i].first;
    curs += tokens[i].first;
    if (i + 1 < tokens.size()) {
      auto v1 = parse_tokens(curs).first;
      auto v2 = parse_tokens(tokens[i + 1].first).first;
      for (auto v : v2) v1.push_back(v);
      auto [v3, res] = parse_tokens(curs + tokens[i + 1].first);
      if (!res || v1 != v3) {
        cout << ' ';
        curs.clear();
      }
    }
  }
  cout << '\n';
  return 0;
}
