#include <bits/stdc++.h>
using namespace std;
string last_w = "";
set<string> reserved;
void change_last_w() {
  do {
    int j(last_w.size() - 1);
    while (j >= 0 && last_w[j] == 'z') --j;
    if (j == -1)
      last_w.assign(last_w.size() + 1, 'a');
    else {
      ++last_w[j];
      for (int i(j + 1); i < last_w.size(); ++i) last_w[i] = 'a';
    }
  } while (reserved.count(last_w));
}
bool valid_char(char c) {
  return isdigit(c) || isalpha(c) || c == '_' || c == '$';
}
int parse_word(const string& s) {
  if (s.empty()) return 0;
  if (isdigit(s[0])) return false;
  int ans(0);
  while (ans < s.size() && valid_char(s[ans])) ++ans;
  return ans;
}
int parse_num(const string& s) {
  if (s.empty()) return 0;
  int ans(0);
  while (ans < s.size() && isdigit(s[ans])) ++ans;
  return ans;
}
int parse_reserved(const string& s) {
  if (s.empty()) return 0;
  int best(0);
  string t;
  for (int i(0); i < min<size_t>(20UL, s.size()) && s[i] != '#'; ++i) {
    t += s[i];
    if (reserved.count(t)) best = i + 1;
  }
  return best;
}
int parse_all(const string& s) {
  return max({parse_num(s), parse_reserved(s), parse_word(s)});
}
vector<string> parse(string s) {
  vector<string> ans;
  while (!s.empty() && s[0] != '#') {
    int cnt(0);
    while (cnt < s.size() && s[cnt] == ' ') ++cnt;
    if (cnt) {
      s = s.substr(cnt, s.size() - cnt);
      continue;
    }
    int cur(parse_all(s));
    ans.push_back(s.substr(0, cur));
    s = s.substr(cur, s.size() - cur);
  }
  return ans;
}
vector<int> parse_len(string s) {
  vector<int> ans;
  while (!s.empty()) {
    int cnt(0);
    while (cnt < s.size() && s[cnt] == ' ') ++cnt;
    if (cnt) {
      s = s.substr(cnt, s.size() - cnt);
      continue;
    }
    int cur(parse_all(s));
    ans.push_back(cur);
    s = s.substr(cur, s.size() - cur);
  }
  return ans;
}
int main() {
  ios_base::sync_with_stdio(false);
  int n;
  cin >> n;
  string s__;
  for (int i(0); i < n; ++i) {
    cin >> s__;
    reserved.insert(s__);
  }
  cin >> n;
  getline(cin, s__);
  vector<string> tokens;
  while (n--) {
    getline(cin, s__);
    auto add = parse(s__);
    copy(begin(add), end(add), back_inserter(tokens));
  }
  map<string, string> was;
  for (string& s : tokens)
    if (!reserved.count(s) && !isdigit(s[0])) {
      if (!was.count(s)) {
        change_last_w();
        was[s] = last_w;
      }
      s = was[s];
    }
  string ans;
  int next_space(tokens.size());
  for (int i(0); i < tokens.size(); ++i) {
    string s(tokens[i]);
    int j(i + 1);
    while (true) {
      if (j == tokens.size()) break;
      s += tokens[j];
      if (parse_all(s) != tokens[i].size()) {
        next_space = min(next_space, j - 1);
        break;
      }
      if (s.size() > 20) break;
      ++j;
    }
    ans += tokens[i];
    if (next_space == i) {
      next_space = tokens.size();
      ans += ' ';
    }
  }
  cout << ans;
}
