#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
struct obj {
  string name;
  int cls;
  int p[3], sz;
  obj() { p[0] = p[1] = p[2] = 0; }
} o[100];
struct res {
  string name;
  int type, bonus;
  int home;
  bool operator<(const res& x) const { return bonus > x.bonus; }
} r[1000];
void output(int index, int n, int m) {
  int best = -1, ind = -1, i;
  vector<string> residents;
  for (i = 0; i < n; i++)
    if (o[i].cls == index && best < o[i].p[index]) {
      best = o[i].p[index];
      ind = i;
    }
  cout << o[ind].name << " ";
  for (i = 0; i < m; i++)
    if (r[i].home == ind) residents.push_back(r[i].name);
  cout << residents.size();
  for (i = 0; i < residents.size(); i++) cout << " " << residents[i];
  cout << endl;
}
vector<int> taken[100];
bool u[1000];
void make(int index, int n, int m) {
  int i, j, k, best = -1, ind = -1;
  vector<int> ob;
  for (i = 0; i < n; i++) {
    if (o[i].cls == index) ob.push_back(i);
  }
  vector<int> rs;
  for (i = 0; i < m && rs.size() < 10; i++)
    if (r[i].type == index) rs.push_back(i);
  for (i = 0; i < ob.size(); i++) {
    int cur = o[ob[i]].p[index];
    for (j = 0; j < o[ob[i]].sz && j < rs.size(); j++) cur += r[rs[j]].bonus;
    if (cur > best) {
      best = cur;
      ind = ob[i];
    }
  }
  for (j = 0; j < o[ind].sz && j < rs.size(); j++) {
    taken[ind].push_back(rs[j]);
    o[ind].p[index] += r[rs[j]].bonus;
    r[rs[j]].home = ind;
    u[rs[j]] = true;
  }
}
int main() {
  int n, m, i, j, k, totalSize = 0;
  string s;
  cin >> n;
  for (i = 0; i < n; i++) {
    cin >> o[i].name;
    cin >> s;
    if (s == "weapon") o[i].cls = 0;
    if (s == "armor") o[i].cls = 1;
    if (s == "orb") o[i].cls = 2;
    cin >> o[i].p[0] >> o[i].p[1] >> o[i].p[2] >> o[i].sz;
    totalSize += o[i].sz;
  }
  cin >> m;
  for (i = 0; i < m; i++) {
    cin >> r[i].name;
    cin >> s;
    if (s == "gladiator") r[i].type = 0;
    if (s == "sentry") r[i].type = 1;
    if (s == "physician") r[i].type = 2;
    cin >> r[i].bonus;
    cin >> s;
    for (j = 0; j < n; j++)
      if (o[j].name == s) {
        r[i].home = j;
        break;
      }
  }
  if (totalSize == m) {
    for (i = 0; i < m; i++) o[r[i].home].p[r[i].type] += r[i].bonus;
  } else {
    sort(r, r + m);
    make(0, n, m);
    make(1, n, m);
    make(2, n, m);
    for (i = 0; i < m; i++)
      if (!u[i])
        for (j = 0; j < n; j++)
          if (o[j].sz > taken[j].size()) {
            taken[j].push_back(i);
            r[i].home = j;
            break;
          }
  }
  output(0, n, m);
  output(1, n, m);
  output(2, n, m);
  return 0;
}
