#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
using namespace std;
mt19937_64 mt_rand(chrono::system_clock::now().time_since_epoch().count());
template <typename T1, typename T2>
inline bool upmax(T1& a, T2 b) {
  return (a < b ? (a = b, true) : false);
}
template <typename T1, typename T2>
inline bool upmin(T1& a, T2 b) {
  return (b < a ? (a = b, true) : false);
}
const int maxn = (int)1e6 + 10;
const int maxlog = 21;
const int base = (int)1e9 + 7;
const long double eps = (long double)1e-10;
const long double PI = acos(-1.);
const int pp = 41;
struct Parser {
  set<string> tokens;
  Parser(){};
  explicit Parser(set<string> tokens) : tokens(move(tokens)) {}
  bool isdigit(char c) { return '0' <= c && c <= '9'; }
  bool issymbol(char c) {
    if ('a' <= c && c <= 'z') {
      return 1;
    } else if ('A' <= c && c <= 'Z') {
      return 1;
    } else if (c == '$') {
      return 1;
    } else if (c == '_') {
      return 1;
    } else if ('0' <= c && c <= '9') {
      return 1;
    }
    return 0;
  }
  bool isnumber(const string& s) {
    bool ok = true;
    for (int i = 0; i < ((int)(s).size()) && ok; i++) {
      ok &= '0' <= s[i] && s[i] <= '9';
    }
    return ok;
  }
  bool isword(const string& s) {
    bool ok = true;
    for (int i = 0; i < ((int)(s).size()) && ok; i++) {
      if ('a' <= s[i] && s[i] <= 'z') {
        ok &= 1;
      } else if ('A' <= s[i] && s[i] <= 'Z') {
        ok &= 1;
      } else if (s[i] == '$') {
        ok &= 1;
      } else if (s[i] == '_') {
        ok &= 1;
      } else if ('0' <= s[i] && s[i] <= '9' && i != 0) {
        ok &= 1;
      } else
        ok &= 0;
    }
    return ok;
  }
  bool isreserved(const string& s) { return tokens.count(s); }
  vector<string> parse(const string& s, bool& ok) {
    int n = ((int)(s).size());
    string curToken, lastToken, name, tokenFrom;
    vector<string> answer;
    ok = true;
    for (int i = 0; i < n; i++) {
      if (s[i] == '#') break;
      if (s[i] == ' ') continue;
      curToken = "";
      lastToken = "";
      tokenFrom = "";
      name = "";
      int lastpos = i;
      bool number = isdigit(s[i]);
      bool word = issymbol(s[i]) && !isdigit(s[i]);
      bool isres = 1;
      for (int j = i; j < n && (isres || word || number); j++) {
        if (s[j] == ' ') {
          break;
        }
        curToken += s[j];
        if (j - i <= 20 && isreserved(curToken)) {
          lastToken = curToken;
          lastpos = j;
        }
        if (j - i > 20) isres = false;
        if (number && isdigit(s[j])) {
          lastToken = curToken;
          lastpos = j;
        } else
          number = false;
        if (word && issymbol(s[j])) {
          lastToken = curToken;
          lastpos = j;
        } else
          word = false;
      }
      if (lastToken.empty() && s[i] != ' ') {
        ok = false;
        return answer;
      }
      answer.push_back(lastToken);
      i = lastpos;
    }
    return answer;
  }
};
struct Minimizer {
  Parser parser;
  vector<string> savedtokens;
  map<string, string> mapto;
  int curMask = 0;
  int curLen = 1;
  Minimizer() {}
  explicit Minimizer(Parser parser) : parser(move(parser)) {}
  bool AddLine(const string& s) {
    bool ok;
    auto add = parser.parse(s, ok);
    if (!ok) return ok;
    for (auto& v : add) {
      savedtokens.push_back(v);
    }
    return ok;
  }
  string getName() {
    string res;
    int msk = curMask;
    for (int i = 0; i < curLen; i++) {
      res += char('a' + msk % 26);
      msk /= 26;
    }
    reverse((res).begin(), (res).end());
    return res;
  }
  void apply() {
    curMask++;
    int p = 1;
    for (int i = 0; i < curLen; i++) p *= 26;
    if (curMask >= p) curMask = 0, curLen++;
  }
  string nameGen() {
    string name;
    while (parser.isreserved(name = getName())) {
      apply();
    }
    return name;
  }
  string GetMinimized() {
    string answer, lastToken;
    vector<string> curtokens;
    for (auto& token : savedtokens) {
      if (parser.isreserved(token) || parser.isnumber(token)) {
        continue;
      } else if (parser.isword(token)) {
        if (mapto.count(token)) {
          token = mapto[token];
        } else {
          token = mapto[token] = nameGen();
          apply();
        }
      }
    }
    int cntTks = 0;
    for (auto& token : savedtokens) {
      string res = lastToken + token;
      curtokens.push_back(token);
      bool ok;
      auto tks = parser.parse(res, ok);
      if (((int)(tks).size()) == cntTks + 1 && tks.back() == token) {
        lastToken += token;
        cntTks++;
        answer += token;
      } else {
        lastToken = token;
        cntTks = 1;
        answer += " " + token;
      }
    }
    return answer;
  }
};
int n, m;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cin >> n;
  set<string> tokens;
  for (int i = 0; i < n; i++) {
    string token;
    cin >> token;
    tokens.insert(token);
  }
  Parser p(tokens);
  Minimizer miner(p);
  cin >> m;
  string line;
  getline(cin, line);
  for (int i = 0; i < m; i++) {
    getline(cin, line);
    bool ok = miner.AddLine(line);
    if (!ok) {
      exit(228);
      cout << "TTRROOOTLLLE!!!\n";
      return 0;
    }
  }
  cout << miner.GetMinimized() << '\n';
  return 0;
}
