#include <bits/stdc++.h>
using namespace std;
bool MOVE = false;
struct hero {
  string name;
  int val, size;
  vector<string> live, use;
  hero(string _name = "", int _val = 0, int _size = 0) {
    name = _name;
    val = _val;
    size = _size;
  }
};
struct power {
  string name;
  int val;
  power(string _name = "", int _val = 0) {
    name = _name;
    val = _val;
  }
  bool operator<(const power& w) const { return val > w.val; }
};
int n, m;
vector<hero> H[3];
vector<power> P[3];
map<string, int> INP[3];
map<string, pair<int, int> > POS;
vector<string> ALL;
int PALL = 0;
void read() {
  cin >> n;
  for (int i = 0; i < n; ++i) {
    string name, type;
    int pw, pa, po, size;
    cin >> name >> type >> pw >> pa >> po >> size;
    if (type == "weapon") {
      H[0].push_back(hero(name, pw, size));
      POS[name] = make_pair(0, H[0].size() - 1);
    }
    if (type == "armor") {
      H[1].push_back(hero(name, pa, size));
      POS[name] = make_pair(1, H[1].size() - 1);
    }
    if (type == "orb") {
      H[2].push_back(hero(name, po, size));
      POS[name] = make_pair(2, H[2].size() - 1);
    }
  }
  cin >> m;
  for (int i = 0; i < m; ++i) {
    string name, type, place;
    int val;
    cin >> name >> type >> val >> place;
    ALL.push_back(name);
    H[POS[place].first][POS[place].second].live.push_back(name);
    if (type == "gladiator") {
      P[0].push_back(power(name, val));
      INP[0][name] = val;
    }
    if (type == "sentry") {
      P[1].push_back(power(name, val));
      INP[1][name] = val;
    }
    if (type == "physician") {
      P[2].push_back(power(name, val));
      INP[2][name] = val;
    }
  }
  sort(P[0].begin(), P[0].end());
  sort(P[1].begin(), P[1].end());
  sort(P[2].begin(), P[2].end());
  for (int i = 0; i < H[0].size(); ++i)
    if (H[0][i].live.size() < H[0][i].size) MOVE = true;
  for (int i = 0; i < H[1].size(); ++i)
    if (H[1][i].live.size() < H[1][i].size) MOVE = true;
  for (int i = 0; i < H[2].size(); ++i)
    if (H[2][i].live.size() < H[2][i].size) MOVE = true;
}
hero BW("", -1), BA("", -1), BO("", -1);
hero POWER_WEAPON(hero w) {
  for (int i = 0; i < P[0].size(); ++i) {
    if (w.use.size() >= w.size) break;
    w.val += P[0][i].val;
    w.use.push_back(P[0][i].name);
  }
  return w;
}
hero POWER_ARMOR(hero w) {
  for (int i = 0; i < P[1].size(); ++i) {
    if (w.use.size() >= w.size) break;
    w.val += P[1][i].val;
    w.use.push_back(P[1][i].name);
  }
  return w;
}
hero POWER_ORB(hero w) {
  for (int i = 0; i < P[2].size(); ++i) {
    if (w.use.size() >= w.size) break;
    w.val += P[2][i].val;
    w.use.push_back(P[2][i].name);
  }
  return w;
}
set<string> BAN;
int main() {
  read();
  if (!MOVE) {
    for (int i = 0; i < H[0].size(); ++i)
      for (int j = 0; j < H[0][i].live.size(); ++j)
        H[0][i].val += INP[0][H[0][i].live[j]];
    for (int i = 0; i < H[1].size(); ++i)
      for (int j = 0; j < H[1][i].live.size(); ++j)
        H[1][i].val += INP[1][H[1][i].live[j]];
    for (int i = 0; i < H[2].size(); ++i)
      for (int j = 0; j < H[2][i].live.size(); ++j)
        H[2][i].val += INP[2][H[2][i].live[j]];
    for (int i = 0; i < H[0].size(); ++i)
      if (BW.val < H[0][i].val) BW = H[0][i];
    for (int i = 0; i < H[1].size(); ++i)
      if (BA.val < H[1][i].val) BA = H[1][i];
    for (int i = 0; i < H[2].size(); ++i)
      if (BO.val < H[2][i].val) BO = H[2][i];
    cout << BW.name << ' ' << BW.live.size();
    for (int i = 0; i < BW.live.size(); ++i) cout << ' ' << BW.live[i];
    cout << '\n';
    cout << BA.name << ' ' << BA.live.size();
    for (int i = 0; i < BA.live.size(); ++i) cout << ' ' << BA.live[i];
    cout << '\n';
    cout << BO.name << ' ' << BO.live.size();
    for (int i = 0; i < BO.live.size(); ++i) cout << ' ' << BO.live[i];
    cout << '\n';
  } else {
    for (int i = 0; i < H[0].size(); ++i) {
      hero neo = POWER_WEAPON(H[0][i]);
      if (neo.val > BW.val) BW = neo;
    }
    for (int i = 0; i < H[1].size(); ++i) {
      hero neo = POWER_ARMOR(H[1][i]);
      if (neo.val > BA.val) BA = neo;
    }
    for (int i = 0; i < H[2].size(); ++i) {
      hero neo = POWER_ORB(H[2][i]);
      if (neo.val > BO.val) BO = neo;
    }
    for (int i = 0; i < BW.use.size(); ++i) BAN.insert(BW.use[i]);
    for (int i = 0; i < BA.use.size(); ++i) BAN.insert(BA.use[i]);
    for (int i = 0; i < BO.use.size(); ++i) BAN.insert(BO.use[i]);
    while (BW.use.size() < BW.size && PALL < ALL.size()) {
      if (BAN.count(ALL[PALL])) {
        ++PALL;
        continue;
      }
      BW.use.push_back(ALL[PALL]);
      ++PALL;
    }
    while (BA.use.size() < BA.size && PALL < ALL.size()) {
      if (BAN.count(ALL[PALL])) {
        ++PALL;
        continue;
      }
      BA.use.push_back(ALL[PALL]);
      ++PALL;
    }
    while (BO.use.size() < BO.size && PALL < ALL.size()) {
      if (BAN.count(ALL[PALL])) {
        ++PALL;
        continue;
      }
      BO.use.push_back(ALL[PALL]);
      ++PALL;
    }
    cout << BW.name << ' ' << BW.use.size();
    for (int i = 0; i < BW.use.size(); ++i) cout << ' ' << BW.use[i];
    cout << '\n';
    cout << BA.name << ' ' << BA.use.size();
    for (int i = 0; i < BA.use.size(); ++i) cout << ' ' << BA.use[i];
    cout << '\n';
    cout << BO.name << ' ' << BO.use.size();
    for (int i = 0; i < BO.use.size(); ++i) cout << ' ' << BO.use[i];
    cout << '\n';
  }
  return 0;
}
