#include <bits/stdc++.h>
using namespace std;
const int N = 20;
set<string> reserved;
int n, m;
int parse_reserved(const string &s, int it) {
  int res = 0;
  string cur;
  for (int i = it; i < it + 20 && i < s.size() && s[i] != '#'; i++) {
    cur += s[i];
    if (reserved.count(cur)) res = i - it + 1;
  }
  return res;
}
int parse_number(const string &s, int it) {
  int res = 0;
  while (it + res < s.size() && isdigit(s[it + res])) ++res;
  return res;
}
bool is_valid(char c) {
  return isdigit(c) || isalpha(c) || c == '_' || c == '$';
}
int parse_word(const string &s, int it) {
  if (isdigit(s[it])) return 0;
  int res = 0;
  while (it + res < s.size() && is_valid(s[it + res])) ++res;
  return res;
}
int parse(const string &s, int it) {
  return max(max(parse_reserved(s, it), parse_number(s, it)),
             parse_word(s, it));
}
string getnext(string s) {
  do {
    int i = (int)s.size() - 1;
    while (i >= 0 && s[i] == 'z') i--;
    if (i != -1) {
      ++s[i];
      for (int j = i + 1; j < s.size(); j++) s[j] = 'a';
    } else
      s = string(s.size() + 1, 'a');
  } while (reserved.count(s));
  return s;
}
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    string str;
    cin >> str;
    reserved.insert(str);
  }
  vector<string> tokens;
  cin >> m;
  string tmp;
  getline(cin, tmp);
  string last = "";
  while (m--) {
    string str;
    getline(cin, str);
    for (int i = 0; i < str.size(); i++) {
      if (str[i] == ' ') continue;
      if (str[i] == '#') break;
      int len = parse(str, i);
      tokens.push_back(str.substr(i, len));
      i += len - 1;
    }
  }
  unordered_map<string, string> change;
  for (auto &x : tokens) {
    if (!reserved.count(x) && !isdigit(x[0])) {
      if (change.find(x) == change.end()) {
        last = getnext(last);
        change[x] = last;
      }
      x = change[x];
    }
  }
  int p = tokens.size();
  for (int i = 0; i < tokens.size(); i++) {
    string cur = tokens[i];
    for (int j = i + 1; j < tokens.size(); j++) {
      cur += tokens[j];
      if (parse(cur, 0) != tokens[i].size()) {
        p = min(p, j - 1);
        break;
      }
      if (cur.size() > 20) break;
    }
    cout << tokens[i];
    if (i == p) {
      cout << " ";
      p = tokens.size();
    }
  }
  return 0;
}
