#include <bits/stdc++.h>
using namespace std;
int n, m;
int k;
bool debug = false;
class rdt {
 public:
  string name, type, home;
  int bonus;
  bool operator<(const rdt b) const { return bonus > b.bonus; }
};
class item {
 public:
  string name, cls;
  int atk, def, res, size, ans = 0;
  vector<rdt> rs, rsAns;
  void pp() {
    printf("%s %d ", &name[0], rs.size());
    for (auto x : rs) cout << x.name << " ";
    puts("");
  }
};
map<string, item> wps;
map<string, rdt> rzds;
map<string, vector<rdt>> sortR;
map<string, int> cc, setdown;
item *A, *D, *R;
bool judgeSame(string cls, string type) {
  return (cls == "weapon" && type == "gladiator") ||
         (cls == "armor" && type == "sentry") ||
         (cls == "orb" && type == "physician");
}
string changeType(string type) {
  if (type == "gladiator") return "weapon";
  if (type == "sentry") return "armor";
  if (type == "physician") return "orb";
  return "";
}
void gg() {
  auto ii = rzds.begin();
  for (auto &x : wps) {
    item *i = &x.second;
    while (i->size > i->rs.size()) {
      while (ii != rzds.end() && setdown[ii->first]) ii++;
      if (ii == rzds.end()) return;
      i->rs.push_back(ii->second);
      setdown[ii->first] = 1;
    }
    if (ii == rzds.end()) return;
  }
}
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    item im;
    cin >> im.name >> im.cls >> im.atk >> im.def >> im.res >> im.size;
    wps[im.name] = im;
  }
  cin >> k;
  for (int i = 1; i <= k; i++) {
    rdt r;
    cin >> r.name >> r.type >> r.bonus >> r.home;
    rzds[r.name] = r;
    cc[r.home]++;
    wps[r.home].rs.push_back(r);
    if (judgeSame(wps[r.home].cls, r.type)) wps[r.home].ans += r.bonus;
    sortR[changeType(r.type)].push_back(r);
  }
  bool fl = 0;
  for (auto x : wps) {
    if (x.second.size != cc[x.first]) fl = 1;
  }
  if (fl) {
    for (auto &x : sortR) {
      vector<rdt> &v = x.second;
      sort(v.begin(), v.end());
    }
    for (auto &x : wps) {
      item *i = &x.second;
      i->rs.clear();
      i->ans = 0;
      for (int j = 0; j < i->size && j < sortR[i->cls].size(); j++) {
        i->rs.push_back(sortR[i->cls][j]);
        i->ans += sortR[i->cls][j].bonus;
      }
      if (i->cls == "weapon") {
        i->ans += i->atk;
        if (A == NULL || A->ans < i->ans) A = i;
      } else if (i->cls == "armor") {
        i->ans += i->def;
        if (D == NULL || D->ans < i->ans) D = i;
      } else {
        i->ans += i->res;
        if (R == NULL || R->ans < i->ans) R = i;
      }
    }
    for (rdt r : A->rs) setdown[r.name] = 1;
    for (rdt r : D->rs) setdown[r.name] = 1;
    for (rdt r : R->rs) setdown[r.name] = 1;
    gg();
  } else {
    for (auto &x : wps) {
      item *i = &x.second;
      if (i->cls == "weapon") {
        i->ans += i->atk;
        if (A == NULL || A->ans < i->ans) A = i;
      } else if (i->cls == "armor") {
        i->ans += i->def;
        if (D == NULL || D->ans < i->ans) D = i;
      } else {
        i->ans += i->res;
        if (R == NULL || R->ans < i->ans) R = i;
      }
    }
  }
  A->pp();
  D->pp();
  R->pp();
  return 0;
}
