#include <bits/stdc++.h>
using namespace std;
int N;
set<string> Tokens;
char buf[1010];
string erase_spaces(string e) {
  string res;
  for (char f : e)
    if (f != ' ' && f != '\t' && f != '\n') res.push_back(f);
  return res;
}
vector<string> parse() {
  vector<string> res;
  for (int i = 0; buf[i]; i++) {
    if (buf[i] == '#') {
      for (int j = i; buf[j]; j++) buf[j] = 0;
      break;
    }
  }
  for (char *p = strtok(buf, " "); p; p = strtok(NULL, " ")) {
    res.push_back(erase_spaces((string)p));
  }
  return res;
}
int check_norm(char c) {
  if (isdigit(c)) return 1;
  if ('a' <= c && c <= 'z') return 1;
  if ('A' <= c && c <= 'Z') return 1;
  if (c == '_' || c == '$') return 1;
  return 0;
}
int chk_token(string t, int c = 0) {
  if (c == 0 && Tokens.find(t) != Tokens.end()) return 1;
  int dok = 1;
  for (char c : t)
    if (!isdigit(c)) dok = 0;
  if (dok) return 2;
  if ((int)t.size() && !isdigit(t[0])) {
    dok = 1;
    for (char c : t)
      if (!check_norm(c)) dok = 0;
    if (dok) return 3;
  }
  return 0;
}
vector<string> parse_token(vector<string> &L) {
  vector<string> res;
  for (string e : L) {
    while ((int)e.size() > 0) {
      string r = e;
      while ((int)r.size() > 0) {
        if (chk_token(r)) {
          res.push_back(r);
          string ne;
          for (int i = (int)r.size(); i < (int)e.size(); i++)
            ne.push_back(e[i]);
          e = ne;
          break;
        } else
          r.pop_back();
      }
    }
  }
  return res;
}
void input_line() {
  fgets(buf, 1010, stdin);
  int L = (int)strlen(buf);
  if (buf[L - 1] == 0) buf[--L] = 0;
}
int main() {
  input_line();
  N = atoi(buf);
  input_line();
  auto v = parse();
  for (string e : v) Tokens.insert(e);
  int M;
  input_line();
  M = atoi(buf);
  vector<string> X;
  for (int i = 0; i < M; i++) {
    input_line();
    auto v = parse();
    for (auto e : v) X.push_back(e);
  }
  vector<string> Y = parse_token(X);
  vector<string> m, q;
  for (int i = 0; i < 26; i++) {
    string rr;
    rr.push_back('a' + i);
    q.push_back(rr);
    if (Tokens.find(rr) == Tokens.end()) m.push_back(rr);
  }
  for (int i = 0; i < (int)q.size(); i++) {
    if ((int)m.size() > (int)Y.size()) break;
    string e = q[i];
    for (int j = 0; j < 26; j++) {
      string f = e;
      f.push_back('a' + j);
      if (Tokens.find(f) == Tokens.end()) m.push_back(f);
      q.push_back(f);
    }
  }
  int cm = 0;
  map<string, string> Mx;
  for (string &e : Y) {
    if (chk_token(e) == 3) {
      if (Mx.find(e) == Mx.end()) Mx[e] = m[cm++];
      e = Mx[e];
    }
  }
  int L = (int)Y.size();
  vector<pair<int, int> > px;
  for (int i = 0; i < L; i++) {
    string now = Y[i];
    int r = chk_token(now, 1);
    for (int j = i + 1; j < L; j++) {
      int ok = 0;
      for (int k = 0; k < (int)Y[j].size(); k++) {
        now.push_back(Y[j][k]);
        if (r == 2 && !isdigit(Y[j][k])) r = 0;
        if (r == 3 && !check_norm(Y[j][k])) r = 0;
        if (r != 0 || Tokens.find(now) != Tokens.end()) {
          ok = 1;
          break;
        }
      }
      if (ok) {
        px.push_back(pair<int, int>(i + 1, j));
      }
    }
  }
  sort(px.begin(), px.end(),
       [](pair<int, int> a, pair<int, int> b) { return a.second < b.second; });
  int cc[100010] = {};
  for (pair<int, int> e : px) {
    int exi = 0;
    for (int i = e.first; i <= e.second; i++) exi |= cc[i];
    if (exi) continue;
    cc[e.second] = 1;
  }
  for (int i = 0; i < L; i++) {
    printf("%s", Y[i].c_str());
    if (cc[i + 1]) printf(" ");
    if (i == L - 1) puts("");
  }
  return 0;
}
