#include <bits/stdc++.h>
using namespace std;
const int INF = 2147483647;
const long long LLINF = 9223372036854775807LL;
struct item {
  string name, cl;
  int atk, def, res, size;
  int cr;
};
struct res {
  string name, type, home;
  int bonus;
  bool operator<(const res &r2) const {
    if (bonus != r2.bonus) return bonus < r2.bonus;
    return name < r2.name;
  }
};
const int maxn = 1010;
item a[maxn];
res r[maxn];
int vatk[maxn], vdef[maxn], vres[maxn];
int catk = 0, cdef = 0, cres = 0;
int main() {
  int n;
  scanf("%d", &n);
  int totalsz = 0;
  map<string, int> ind;
  for (int i = 0; i < n; ++i) {
    cin >> a[i].name >> a[i].cl;
    ind[a[i].name] = i;
    scanf("%d%d%d%d", &a[i].atk, &a[i].def, &a[i].res, &a[i].size);
    a[i].cr = 0;
    totalsz += a[i].size;
  }
  int k;
  scanf("%d", &k);
  for (int i = 0; i < k; ++i) {
    cin >> r[i].name >> r[i].type >> r[i].bonus >> r[i].home;
    a[ind[r[i].home]].cr++;
  }
  if (totalsz == k) {
    for (int i = 0; i < k; ++i) {
      if (r[i].type[0] == 'g') a[ind[r[i].home]].atk += r[i].bonus;
      if (r[i].type[0] == 's') a[ind[r[i].home]].def += r[i].bonus;
      if (r[i].type[0] == 'p') a[ind[r[i].home]].res += r[i].bonus;
    }
    int bi = -1;
    int bj = -1;
    int bk = -1;
    int vi = -1;
    int vj = -1;
    int vk = -1;
    for (int ww = 0; ww < n; ++ww)
      for (int aa = 0; aa < n; ++aa)
        for (int oo = 0; oo < n; ++oo) {
          if (a[ww].cl[0] != 'w') continue;
          if (a[aa].cl[0] != 'a') continue;
          if (a[oo].cl[0] != 'o') continue;
          int ci = a[ww].atk;
          int cj = a[aa].def;
          int ck = a[oo].res;
          if (make_pair(make_pair(ci, cj), ck) >
              make_pair(make_pair(vi, vj), vk)) {
            bi = ww;
            bj = aa;
            bk = oo;
            vi = ci;
            vj = cj;
            vk = ck;
          }
        }
    cout << a[bi].name << " " << a[bi].cr;
    for (int i = 0; i < k; ++i)
      if (r[i].home == a[bi].name) cout << " " << r[i].name;
    cout << endl;
    cout << a[bj].name << " " << a[bj].cr;
    for (int i = 0; i < k; ++i)
      if (r[i].home == a[bj].name) cout << " " << r[i].name;
    cout << endl;
    cout << a[bk].name << " " << a[bk].cr;
    for (int i = 0; i < k; ++i)
      if (r[i].home == a[bk].name) cout << " " << r[i].name;
    cout << endl;
  } else {
    set<res> s1, s2, s3;
    for (int i = 0; i < k; ++i)
      if (r[i].type[0] == 'g')
        s1.insert(r[i]), vatk[catk++] = r[i].bonus;
      else if (r[i].type[0] == 's')
        s2.insert(r[i]), vdef[cdef++] = r[i].bonus;
      else if (r[i].type[0] == 'p')
        s3.insert(r[i]), vres[cres++] = r[i].bonus;
    sort(vatk, vatk + catk);
    reverse(vatk, vatk + catk);
    sort(vdef, vdef + cdef);
    reverse(vdef, vdef + cdef);
    sort(vres, vres + cres);
    reverse(vres, vres + cres);
    for (int i = 1; i < catk; ++i) vatk[i] += vatk[i - 1];
    for (int i = 1; i < cdef; ++i) vdef[i] += vdef[i - 1];
    for (int i = 1; i < cres; ++i) vres[i] += vres[i - 1];
    int bi = -1;
    int bj = -1;
    int bk = -1;
    int vi = -1;
    int vj = -1;
    int vk = -1;
    for (int ww = 0; ww < n; ++ww)
      for (int aa = 0; aa < n; ++aa)
        for (int oo = 0; oo < n; ++oo) {
          if (a[ww].cl[0] != 'w') continue;
          if (a[aa].cl[0] != 'a') continue;
          if (a[oo].cl[0] != 'o') continue;
          int ci =
              a[ww].atk + (catk == 0 ? 0 : vatk[min(catk, a[ww].size) - 1]);
          int cj =
              a[aa].def + (cdef == 0 ? 0 : vdef[min(cdef, a[aa].size) - 1]);
          int ck =
              a[oo].res + (cres == 0 ? 0 : vres[min(cres, a[oo].size) - 1]);
          if (make_pair(make_pair(ci, cj), ck) >
              make_pair(make_pair(vi, vj), vk)) {
            bi = ww;
            bj = aa;
            bk = oo;
            vi = ci;
            vj = cj;
            vk = ck;
          }
        }
    vector<string> a1, a2, a3;
    for (int i = 0; i < a[bi].size && int((s1).size()); ++i)
      a1.push_back(s1.rbegin()->name), s1.erase(*s1.rbegin());
    for (int i = 0; i < a[bj].size && int((s2).size()); ++i)
      a2.push_back(s2.rbegin()->name), s2.erase(*s2.rbegin());
    for (int i = 0; i < a[bk].size && int((s3).size()); ++i)
      a3.push_back(s3.rbegin()->name), s3.erase(*s3.rbegin());
    queue<string> q;
    while (int((s1).size())) q.push(s1.begin()->name), s1.erase(s1.begin());
    while (int((s2).size())) q.push(s2.begin()->name), s2.erase(s2.begin());
    while (int((s3).size())) q.push(s3.begin()->name), s3.erase(s3.begin());
    while (!q.empty() && int((a1).size()) < a[bi].size)
      a1.push_back(q.front()), q.pop();
    while (!q.empty() && int((a2).size()) < a[bj].size)
      a2.push_back(q.front()), q.pop();
    while (!q.empty() && int((a3).size()) < a[bk].size)
      a3.push_back(q.front()), q.pop();
    cout << a[bi].name << " " << int((a1).size());
    for (int i = 0; i < int((a1).size()); ++i) cout << " " << a1[i];
    cout << endl;
    cout << a[bj].name << " " << int((a2).size());
    for (int i = 0; i < int((a2).size()); ++i) cout << " " << a2[i];
    cout << endl;
    cout << a[bk].name << " " << int((a3).size());
    for (int i = 0; i < int((a3).size()); ++i) cout << " " << a3[i];
    cout << endl;
  }
  return 0;
}
