#include <bits/stdc++.h>
using namespace std;
map<string, pair<int, int> > weapons, armors, orbs;
map<string, pair<int, int> >::iterator it;
map<string, string> homes;
map<string, string>::iterator it1;
vector<pair<int, string> > glads, sentrs, phys;
map<string, int> itemsmap;
map<string, int> itemstype;
string answ, ansa, anso;
vector<string> answitems, ansaitems, ansoitems, nonused;
int main(void) {
  int i, n, m, totalsize, cur, val, a, b, c, d, bonus;
  string home, name, type;
  cin >> n;
  totalsize = 0;
  for (i = 0; i < n; i++) {
    cin >> name >> type >> a >> b >> c >> d;
    if (type == "weapon") {
      weapons[name] = make_pair(a, d);
    } else if (type == "armor") {
      armors[name] = make_pair(b, d);
    } else {
      orbs[name] = make_pair(c, d);
    }
    totalsize += d;
  }
  cin >> m;
  for (i = 0; i < m; i++) {
    cin >> name >> type >> bonus >> home;
    homes[name] = home;
    itemsmap[name] = bonus;
    if (type == "gladiator") {
      glads.push_back(make_pair(bonus, name));
      itemstype[name] = 0;
    } else if (type == "sentry") {
      sentrs.push_back(make_pair(bonus, name));
      itemstype[name] = 1;
    } else {
      phys.push_back(make_pair(bonus, name));
      itemstype[name] = 2;
    }
  }
  if (totalsize == m) {
    val = -1;
    for (it = weapons.begin(); it != weapons.end(); it++) {
      cur = (it->second).first;
      for (it1 = homes.begin(); it1 != homes.end(); it1++) {
        if (it1->second == it->first) {
          if (itemstype[it1->first] == 0) {
            cur += itemsmap[it1->first];
          }
        }
      }
      if (val < cur) {
        val = cur;
        answ = it->first;
      }
    }
    val = -1;
    for (it = armors.begin(); it != armors.end(); it++) {
      cur = (it->second).first;
      for (it1 = homes.begin(); it1 != homes.end(); it1++) {
        if (it1->second == it->first) {
          if (itemstype[it1->first] == 1) {
            cur += itemsmap[it1->first];
          }
        }
      }
      if (val < cur) {
        val = cur;
        ansa = it->first;
      }
    }
    val = -1;
    for (it = orbs.begin(); it != orbs.end(); it++) {
      cur = (it->second).first;
      for (it1 = homes.begin(); it1 != homes.end(); it1++) {
        if (it1->second == it->first) {
          if (itemstype[it1->first] == 2) {
            cur += itemsmap[it1->first];
          }
        }
      }
      if (val < cur) {
        val = cur;
        anso = it->first;
      }
    }
    cout << answ << " " << weapons[answ].second << " ";
    for (it1 = homes.begin(); it1 != homes.end(); it1++) {
      if (it1->second == answ) {
        cout << it1->first << " ";
      }
    }
    cout << endl;
    cout << ansa << " " << armors[ansa].second << " ";
    for (it1 = homes.begin(); it1 != homes.end(); it1++) {
      if (it1->second == ansa) {
        cout << it1->first << " ";
      }
    }
    cout << endl;
    cout << anso << " " << orbs[anso].second << " ";
    for (it1 = homes.begin(); it1 != homes.end(); it1++) {
      if (it1->second == anso) {
        cout << it1->first << " ";
      }
    }
    cout << endl;
    return 0;
  }
  sort(glads.rbegin(), glads.rend());
  sort(sentrs.rbegin(), sentrs.rend());
  sort(phys.rbegin(), phys.rend());
  val = -1;
  for (it = weapons.begin(); it != weapons.end(); it++) {
    cur = (it->second).first;
    for (i = 0; i < (min((it->second).second, (int)glads.size())); i++) {
      cur += glads[i].first;
    }
    if (val < cur) {
      val = cur;
      answ = it->first;
    }
  }
  val = -1;
  for (it = armors.begin(); it != armors.end(); it++) {
    cur = (it->second).first;
    for (i = 0; i < (min((it->second).second, (int)sentrs.size())); i++) {
      cur += sentrs[i].first;
    }
    if (val < cur) {
      val = cur;
      ansa = it->first;
    }
  }
  val = -1;
  for (it = orbs.begin(); it != orbs.end(); it++) {
    cur = (it->second).first;
    for (i = 0; i < (min((it->second).second, (int)phys.size())); i++) {
      cur += phys[i].first;
    }
    if (val < cur) {
      val = cur;
      anso = it->first;
    }
  }
  for (i = 0; i < glads.size(); i++) {
    if (i < weapons[answ].second) {
      answitems.push_back(glads[i].second);
    } else {
      nonused.push_back(glads[i].second);
    }
  }
  for (i = 0; i < sentrs.size(); i++) {
    if (i < armors[ansa].second) {
      ansaitems.push_back(sentrs[i].second);
    } else {
      nonused.push_back(sentrs[i].second);
    }
  }
  for (i = 0; i < phys.size(); i++) {
    if (i < orbs[anso].second) {
      ansoitems.push_back(phys[i].second);
    } else {
      nonused.push_back(phys[i].second);
    }
  }
  int j = 0;
  while (j < nonused.size() && answitems.size() < weapons[answ].second) {
    answitems.push_back(nonused[j++]);
  }
  while (j < nonused.size() && ansaitems.size() < armors[ansa].second) {
    ansaitems.push_back(nonused[j++]);
  }
  while (j < nonused.size() && ansoitems.size() < orbs[anso].second) {
    ansoitems.push_back(nonused[j++]);
  }
  cout << answ << " " << answitems.size() << " ";
  for (i = 0; i < answitems.size(); i++) {
    cout << answitems[i] << " ";
  }
  cout << endl;
  cout << ansa << " " << ansaitems.size() << " ";
  for (i = 0; i < ansaitems.size(); i++) {
    cout << ansaitems[i] << " ";
  }
  cout << endl;
  cout << anso << " " << ansoitems.size() << " ";
  for (i = 0; i < ansoitems.size(); i++) {
    cout << ansoitems[i] << " ";
  }
  cout << endl;
}
