#include <bits/stdc++.h>
using namespace std;
unordered_set<string> reserved;
unordered_map<string, string> words;
enum class type { RES, WORD, NUM };
struct token {
  string str;
  type t;
};
string ind_to_word(int ind) {
  if (ind == 0) return "a";
  string res;
  while (ind > 0) {
    res.insert(0, 1, 'a' + ind % 26 - (res.empty() ? 0 : 1));
    ind /= 26;
  }
  return res;
}
string replace_word(const string &word, int &ind) {
  const auto &it = words.find(word);
  if (it != words.end()) return it->second;
  string res;
  while (reserved.find(res = ind_to_word(ind++)) != reserved.end())
    ;
  words.emplace(word, res);
  return res;
}
void replace_words(vector<token> &tokens) {
  int word_counter = 0;
  for (auto &token : tokens) {
    if (token.t == type::WORD) {
      token.str = replace_word(token.str, word_counter);
    }
  }
}
void skip_space(const string &text, size_t &pos) {
  while (pos < text.length() && text[pos] == ' ') pos++;
}
bool is_num(char ch) { return '0' <= ch && ch <= '9'; }
bool is_word(char ch) {
  return ('a' <= ch && ch <= 'z') || ('A' <= ch && ch <= 'Z') ||
         ('0' <= ch && ch <= '9') || ch == '_' || ch == '$';
}
bool cmp(const vector<token> &a, const vector<token> &b) {
  if (a.size() != b.size()) return false;
  for (size_t i = 0; i < a.size(); ++i)
    if (a[i].str != b[i].str || a[i].t != b[i].t) return false;
  return true;
}
string get_word(const string &s, size_t pos) {
  if (is_num(s[pos])) return "";
  size_t i = 0;
  while (pos + i < s.length() && is_word(s[pos + i])) i++;
  return s.substr(pos, i);
}
string get_num(const string &s, size_t pos) {
  size_t i = 0;
  while (pos + i < s.length() && is_num(s[pos + i])) i++;
  return s.substr(pos, i);
}
string get_res(const string &s, size_t pos) {
  string res;
  for (const string &r : reserved)
    if (r.length() > res.length() && s.compare(pos, r.length(), r) == 0)
      res = r;
  return res;
}
vector<token> parse(const string &text) {
  vector<token> result;
  size_t pos = 0, len = text.length();
  while (pos < len) {
    skip_space(text, pos);
    if (pos >= len) break;
    string w = get_word(text, pos);
    string n = get_num(text, pos);
    string r = get_res(text, pos);
    if (w.length() == 0 && n.length() == 0 && r.length() == 0) {
      result.clear();
      return result;
    }
    if (r.length() >= w.length() && r.length() >= n.length()) {
      result.push_back(token{r, type::RES});
      pos += r.length();
    } else if (w.length() > n.length() && w.length() > r.length()) {
      result.push_back(token{w, type::WORD});
      pos += w.length();
    } else {
      result.push_back(token{n, type::NUM});
      pos += n.length();
    }
  }
  return result;
}
string prev_str;
vector<token> prev_tokens;
void print(const token &tok) {
  prev_tokens.push_back(tok);
  string str = prev_str + tok.str;
  if (prev_str.empty() || cmp(prev_tokens, parse(str))) {
    cout << tok.str;
    prev_str = str;
  } else {
    cout << ' ' << tok.str;
    prev_str = tok.str;
    prev_tokens.clear();
    prev_tokens.push_back(tok);
  }
}
int main() {
  int n, m;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    string str;
    cin >> str;
    reserved.insert(str);
  }
  cin >> m;
  ostringstream ss;
  string l;
  getline(cin, l);
  for (int i = 0; i < m; ++i) {
    getline(cin, l);
    size_t pos = l.find('#');
    l = l.substr(0, pos);
    ss << l << ' ';
  }
  vector<token> tokens = parse(ss.str());
  replace_words(tokens);
  for (const auto &t : tokens) print(t);
  cout << endl;
  return 0;
}
