#include <bits/stdc++.h>
using namespace std;
using namespace std;
const int maxn = 111;
const int maxk = 1111;
const string Item[] = {"weapon", "armor", "orb"};
const string Res[] = {"gladiator", "sentry", "physician"};
struct T {
  string name;
  int type, score, size;
};
struct P {
  string name;
  int type, score, pos;
};
vector<int> have[maxn];
T A[maxn];
P B[maxk];
int N, K;
void inputData() {
  cin >> N;
  for (int i = 0; i < N; ++i) {
    int a[3];
    string CL;
    cin >> A[i].name >> CL;
    A[i].type = find(Item, Item + 3, CL) - Item;
    for (int k = 0; k < 3; ++k) cin >> a[k];
    cin >> A[i].size;
    A[i].score = a[A[i].type];
  }
  cin >> K;
  for (int i = 0; i < K; ++i) {
    string CL, str;
    cin >> B[i].name >> CL;
    B[i].type = find(Res, Res + 3, CL) - Res;
    cin >> B[i].score;
    cin >> str;
    for (int k = 0; k < N; ++k)
      if (str == A[k].name) {
        have[k].push_back(i);
        B[i].pos = k;
        break;
      }
  }
}
int score[maxn];
void Output(int x) {
  cout << A[x].name << " " << (int(have[x].size()));
  for (int i = 0; i < (int(have[x].size())); ++i)
    cout << " " << B[have[x][i]].name;
  cout << endl;
}
void calc(int type) {
  int x = -1;
  for (int i = 0; i < N; ++i)
    if (A[i].type == type) {
      score[i] = A[i].score;
      for (int j = 0; j < (int(have[i].size())); ++j)
        if (B[have[i][j]].type == type) {
          score[i] += B[have[i][j]].score;
        }
      if (x == -1 || score[i] > score[x]) {
        x = i;
      }
    }
  Output(x);
}
int ans[3];
bool mark[maxk];
void solve(int type) {
  vector<pair<int, int> > a;
  for (int i = 0; i < K; ++i)
    if (B[i].type == type) {
      a.push_back(make_pair(-B[i].score, i));
    }
  sort(a.begin(), a.end());
  int x = -1;
  for (int i = 0; i < N; ++i)
    if (A[i].type == type) {
      score[i] = A[i].score;
      have[i].clear();
      for (int j = 0; j < A[i].size && j < (int(a.size())); ++j) {
        score[i] += B[a[j].second].score;
        have[i].push_back(a[j].second);
      }
      if (x == -1 || score[i] > score[x]) {
        x = i;
      }
    }
  ans[type] = x;
  for (int i = 0; i < (int(have[x].size())); ++i) mark[have[x][i]] = true;
}
void main2() {
  int capa = 0;
  for (int i = 0; i < N; ++i) capa += A[i].size;
  if (capa == K) {
    for (int type = 0; type < 3; ++type) calc(type);
    return;
  }
  memset(mark, false, sizeof mark);
  for (int type = 0; type < 3; ++type) {
    solve(type);
  }
  for (int i = 0; i < K; ++i)
    if (!mark[i]) {
      for (int j = 0; j < N; ++j)
        if ((int(have[j].size())) < A[j].size) {
          have[j].push_back(i);
          break;
        }
    }
  for (int type = 0; type < 3; ++type) {
    Output(ans[type]);
  }
}
int main() {
  ios::sync_with_stdio(false);
  inputData();
  main2();
}
