#include <bits/stdc++.h>
using namespace std;
double const pi = 3.1415926535897932384626433832795;
int const inf = (int)1e9;
long long const inf64 = (long long)2e18;
const string pname = "c";
const int NMAX = 1010;
const string TYPE[3] = {"gladiator", "sentry", "physician"};
const string ZN[3] = {"weapon", "armor", "orb"};
int n, m;
string name[NMAX], zn[NMAX], hero[NMAX], type[NMAX], home[NMAX];
int param[NMAX][3], places[NMAX], bonus[NMAX], extra[NMAX];
void answer(int x, int y, int z) {
  cout << name[x] << " " << places[x];
  for (int i = 0; i < (int)m; i++)
    if (home[i] == name[x]) cout << " " << hero[i];
  cout << endl;
  cout << name[y] << " " << places[y];
  for (int i = 0; i < (int)m; i++)
    if (home[i] == name[y]) cout << " " << hero[i];
  cout << endl;
  cout << name[z] << " " << places[z];
  for (int i = 0; i < (int)m; i++)
    if (home[i] == name[z]) cout << " " << hero[i];
  cout << endl;
  exit(0);
}
int get(int now) {
  int best = -1, ans = -1;
  for (int i = 0; i < (int)n; i++)
    if (zn[i] == ZN[now] && best < param[i][now]) best = param[i][now], ans = i;
  return ans;
}
vector<pair<int, int> > q[3];
int ans[3];
int sum[NMAX];
void solve(int now) {
  memset(sum, 0, sizeof(sum));
  sum[0] = 0;
  for (int i = 0; i < (int)q[now].size(); i++)
    sum[i + 1] = sum[i] - q[now][i].first;
  int best = -1, ind = -1;
  for (int i = 0; i < (int)n; i++)
    if (zn[i] == ZN[now]) {
      int tmp = param[i][now] + sum[min((int)q[now].size(), places[i])];
      if (best < tmp) {
        best = tmp;
        ind = i;
      }
    }
  int cnt = min((int)q[now].size(), places[ind]);
  extra[ind] = places[ind] - cnt;
  places[ind] = cnt;
  for (int i = 0; i < (int)cnt; i++) home[q[now][i].second] = name[ind];
  ans[now] = ind;
}
int main() {
  cin >> n;
  int sum = 0;
  for (int i = 0; i < (int)n; i++) {
    cin >> name[i] >> zn[i];
    for (int j = 0; j < (int)3; j++) cin >> param[i][j];
    cin >> places[i];
    sum += places[i];
  }
  cin >> m;
  for (int i = 0; i < (int)m; i++)
    cin >> hero[i] >> type[i] >> bonus[i] >> home[i];
  if (sum == m) {
    for (int i = 0; i < (int)m; i++)
      for (int j = 0; j < (int)n; j++)
        if (name[j] == home[i])
          for (int f = 0; f < (int)3; f++)
            if (TYPE[f] == type[i]) param[j][f] += bonus[i];
    answer(get(0), get(1), get(2));
  }
  for (int i = 0; i < (int)m; i++)
    for (int j = 0; j < (int)3; j++)
      if (type[i] == TYPE[j]) q[j].push_back(make_pair(-bonus[i], i));
  for (int j = 0; j < (int)3; j++) sort((q[j]).begin(), (q[j]).end());
  for (int i = 0; i < (int)m; i++) home[i] = "";
  for (int j = 0; j < (int)3; j++) solve(j);
  for (int i = 0; i < (int)n; i++)
    if (i != ans[0] && i != ans[1] && i != ans[2]) {
      extra[i] = places[i];
      places[i] = 0;
    }
  int yl = 0;
  for (int i = 0; i < (int)m; i++)
    if (home[i] == "") {
      while (extra[yl] == 0) yl++;
      home[i] = name[yl];
      extra[yl]--;
      places[yl]++;
    }
  answer(ans[0], ans[1], ans[2]);
  return 0;
}
