#include <bits/stdc++.h>
using namespace std;
bool iswt(char c) {
  return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') ||
         (c >= '0' && c <= '9') || c == '_' || c == '$';
}
bool isnt(char c) { return c >= '0' && c <= '9'; }
bool isns(string const& s) {
  for (char c : s)
    if (!isnt(c)) return false;
  return true;
}
bool isws(string const& s) {
  for (char c : s)
    if (!iswt(c)) return false;
  return true;
}
string gcw = "a";
void nextw() {
  gcw.back()++;
  int j = (int(gcw.size())) - 1;
  while (j >= 1 && gcw[j] > 'z') {
    gcw[j] = 'a';
    gcw[j - 1]++;
  }
  if (gcw[0] > 'z') gcw = string((int(gcw.size())) + 1, 'a');
}
struct Node {
  char t;
  int i;
  string s;
};
unordered_set<string> res;
int fressz(string const& s) {
  int ans = -1;
  string tmpw;
  for (int i = int(0); i < int((int(s.size()))); ++i) {
    tmpw += s[i];
    if (res.count(tmpw)) ans = max(ans, (int(tmpw.size())));
  }
  return ans;
}
int fnsz(string const& s) {
  int i = 0;
  while (i < (int(s.size())) && isnt(s[i])) ++i;
  return i;
}
int fwsz(string const& s) {
  if (s.empty() || isnt(s[0])) return 0;
  int i = 0;
  while (i < (int(s.size())) && iswt(s[i])) ++i;
  return i;
}
vector<Node> parseit(string s) {
  vector<Node> prs;
  int i = 0;
  while (true) {
    while (i < (int(s.size())) && s[i] == ' ') ++i;
    if (i == (int(s.size())) || s[i] == '#') break;
    bool cn = isnt(s[i]);
    bool cw = iswt(s[i]) && !cn;
    Node nd = {'X', 0, ""};
    string tmpw;
    for (int j = int(i); j < int((int(s.size()))); ++j) {
      if (s[j] == ' ' || s[j] == '#') break;
      tmpw += s[j];
      if (j != i) {
        cn = cn && isnt(s[j]);
        cw = cw && iswt(s[j]);
      }
      if (res.count(tmpw)) {
        nd = Node{'R', i, tmpw};
      } else if (cn) {
        nd = Node{'N', i, tmpw};
      } else if (cw) {
        nd = Node{'W', i, tmpw};
      }
    }
    prs.push_back(nd);
    i += nd.s.size();
  }
  return prs;
}
int main() {
  ios_base::sync_with_stdio(false);
  int nres, M;
  cin >> nres;
  while (nres--) {
    string s;
    cin >> s;
    res.insert(s);
  }
  cin >> M;
  vector<Node> gvn;
  cin.ignore(999, '\n');
  unordered_map<string, string> words;
  for (int m = int(0); m < int(M); ++m) {
    string s;
    getline(cin, s);
    vector<Node> prs = parseit(s);
    for (Node const& n : prs) {
      if (n.t == 'W' && !words.count(n.s)) {
        while (res.count(gcw)) nextw();
        words[n.s] = gcw;
        nextw();
      }
      gvn.push_back(n);
    }
  }
  vector<int> pp(10000);
  string ans, lt;
  for (Node const& n : gvn) {
    string s = n.s;
    if (n.t == 'W') s = words[n.s];
    if (!lt.empty()) {
      bool addspc = false;
      string tt = lt + s;
      if (fnsz(tt) > (int(lt.size())))
        addspc = true;
      else if (fwsz(tt) > (int(lt.size())))
        addspc = true;
      else {
        for (int i = (int(ans.size())) - 1;
             i >= 0 && i >= (int(ans.size())) - 20; --i) {
          if (!pp[i]) continue;
          string ts = ans.substr(i) + s;
          int f = fressz(ts);
          if (f > pp[i]) {
            addspc = true;
            break;
          }
        }
      }
      if (addspc) ans += ' ';
    }
    pp[(int(ans.size()))] = (int(s.size()));
    ans += s;
    lt = s;
  }
  cout << ans << endl;
}
