#include <bits/stdc++.h>
using namespace std;
const int N = 1005;
int n, m;
map<string, int> mp;
string name[N];
int state[N], atk[N], def[N], res[N], sz[N];
string name2[N], buffer;
int state2[N], home[N], bonus[N];
vector<int> sv1[3], sv2[3], acc[3];
int tot = 0;
bool vis[N];
vector<int> resid[N];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> name[i];
    cin >> buffer;
    if (buffer == "armor")
      state[i] = 1;
    else if (buffer == "orb")
      state[i] = 2;
    cin >> atk[i] >> def[i] >> res[i] >> sz[i];
    tot += sz[i];
    sv1[state[i]].push_back(i);
    mp[name[i]] = i;
  }
  cin >> m;
  for (int i = 0; i < m; i++) {
    cin >> name2[i];
    cin >> buffer;
    if (buffer == "sentry")
      state2[i] = 1;
    else if (buffer == "physician")
      state2[i] = 2;
    cin >> bonus[i] >> buffer;
    home[i] = mp[buffer];
    resid[home[i]].push_back(i);
    sv2[state2[i]].push_back(i);
  }
  auto cmp = [](int x, int y) -> bool { return bonus[x] > bonus[y]; };
  for (int i = 0; i < 3; i++) {
    sort(sv2[i].begin(), sv2[i].end(), cmp);
    if (sv2[i].size()) acc[i].push_back(bonus[sv2[i][0]]);
    for (int j = 1; j < sv2[i].size(); j++)
      acc[i].push_back(acc[i].back() + bonus[sv2[i][j]]);
  }
  if (tot == m) {
    vector<int> ans(3);
    vector<int> v(3);
    for (int i = 0; i < sv1[0].size(); i++) {
      for (int j = 0; j < sv1[1].size(); j++) {
        for (int k = 0; k < sv1[2].size(); k++) {
          int ii = sv1[0][i], jj = sv1[1][j], kk = sv1[2][k];
          vector<int> init = {atk[ii], def[jj], res[kk]};
          for (int f = 0; f < sz[ii]; f++)
            if (state2[resid[ii][f]] == 0) init[0] += bonus[resid[ii][f]];
          for (int f = 0; f < sz[jj]; f++)
            if (state2[resid[jj][f]] == 1) init[1] += bonus[resid[jj][f]];
          for (int f = 0; f < sz[kk]; f++)
            if (state2[resid[kk][f]] == 2) init[2] += bonus[resid[kk][f]];
          if (init > ans) {
            ans = init;
            v = {ii, jj, kk};
          }
        }
      }
    }
    for (int j = 0; j < 3; j++) {
      cout << name[v[j]] << ' ' << sz[v[j]];
      for (int i = 0; i < sz[v[j]]; i++) cout << ' ' << name2[resid[v[j]][i]];
      cout << '\n';
    }
    return 0;
  }
  vector<int> ans(3);
  vector<int> v(3);
  for (int i = 0; i < sv1[0].size(); i++) {
    for (int j = 0; j < sv1[1].size(); j++) {
      for (int k = 0; k < sv1[2].size(); k++) {
        int ii = sv1[0][i], jj = sv1[1][j], kk = sv1[2][k];
        vector<int> init = {atk[ii], def[jj], res[kk]};
        if (acc[0].size())
          init[0] += acc[0][min(int(acc[0].size()) - 1, sz[ii] - 1)];
        if (acc[1].size())
          init[1] += acc[1][min(int(acc[1].size()) - 1, sz[jj] - 1)];
        if (acc[2].size())
          init[2] += acc[2][min(int(acc[2].size()) - 1, sz[kk] - 1)];
        if (init > ans) {
          ans = init;
          v = {ii, jj, kk};
        }
      }
    }
  }
  vector<pair<string, vector<string> > > out(3);
  out[0].first = name[v[0]];
  out[1].first = name[v[1]];
  out[2].first = name[v[2]];
  int ii = v[0], jj = v[1], kk = v[2];
  for (int j = 0; j < 3; j++)
    for (int i = 0; i < min(sz[v[j]], int(sv2[j].size())); i++)
      out[j].second.push_back(name2[sv2[j][i]]), vis[sv2[j][i]] = true;
  for (int j = 0; j < 3; j++)
    for (int i = 0; i < m; i++) {
      if (vis[i] || out[j].second.size() == sz[v[j]]) continue;
      out[j].second.push_back(name2[i]);
      vis[i] = true;
    }
  for (int j = 0; j < 3; j++) {
    cout << out[j].first << ' ' << out[j].second.size();
    for (int i = 0; i < out[j].second.size(); i++)
      cout << ' ' << out[j].second[i];
    cout << '\n';
  }
  return 0;
}
