#include <bits/stdc++.h>
using namespace std;
struct T {
  string name;
  int type;
  int par;
  int size;
  vector<string> v;
  void read() {
    string sType;
    int x, y, z;
    cin >> name >> sType >> x >> y >> z >> size;
    if (sType == "weapon") {
      type = 0;
      par = x;
    }
    if (sType == "armor") {
      type = 1;
      par = y;
    }
    if (sType == "orb") {
      type = 2;
      par = z;
    }
  }
};
T pr[1000];
map<string, int> getInd;
vector<pair<int, string> > res[3];
map<string, pair<int, int> > resInd;
int sum[3][1100];
int n, m;
int best[3] = {-1, -1, -1};
int best_par[3];
int pos[1100];
void output() {
  int ind[3] = {-1, -1, -1};
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < pr[i].v.size(); j++)
      if (pr[i].type == resInd[pr[i].v[j]].first)
        pr[i].par += res[pr[i].type][resInd[pr[i].v[j]].second].first;
  }
  for (int i = 0; i < n; i++) {
    if (ind[pr[i].type] == -1 || pr[ind[pr[i].type]].par < pr[i].par)
      ind[pr[i].type] = i;
  }
  for (int i = 0; i < 3; i++) {
    int t = ind[i];
    cout << pr[t].name << " " << pr[t].v.size();
    for (int j = 0; j < pr[t].v.size(); j++) cout << " " << pr[t].v[j];
    cout << endl;
  }
}
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    pr[i].read();
    getInd[pr[i].name] = i;
  }
  cin >> m;
  for (int i = 0; i < m; i++) {
    string name, type, home;
    int par;
    cin >> name >> type >> par >> home;
    int ind = 0;
    if (type == "gladiator") ind = 0;
    if (type == "sentry") ind = 1;
    if (type == "physician") ind = 2;
    res[ind].push_back(make_pair(par, name));
    pr[getInd[home]].v.push_back(name);
    resInd[name] = make_pair(ind, res[ind].size() - 1);
  }
  int count = 0;
  for (int i = 0; i < n; i++) {
    count += pr[i].size;
  }
  if (count == m) {
    output();
    return 0;
  }
  for (int i = 0; i < 3; i++) {
    sort(res[i].begin(), res[i].end());
    reverse(res[i].begin(), res[i].end());
  }
  for (int i = 0; i < 3; i++) {
    sum[i][0] = 0;
    for (int j = 0; j < res[i].size(); j++)
      sum[i][j + 1] = res[i][j].first + sum[i][j];
  }
  for (int i = 0; i < n; i++) {
    int count = res[pr[i].type].size();
    if (count > pr[i].size) count = pr[i].size;
    int S = sum[pr[i].type][count] + pr[i].par;
    if (best[pr[i].type] == -1 || best_par[pr[i].type] < S) {
      best_par[pr[i].type] = S;
      best[pr[i].type] = i;
    }
  }
  for (int i = 0; i < 3; i++) {
    int ind = best[i];
    pr[ind].v.clear();
    int count = res[i].size();
    if (count > pr[ind].size) count = pr[ind].size;
    for (int j = 0; j < count; j++) {
      pr[ind].v.push_back(res[i][j].second);
    }
    pos[i] = count;
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 3; j++) {
      while (pr[i].v.size() < pr[i].size && pos[j] < res[j].size()) {
        pr[i].v.push_back(res[j][pos[j]].second);
        pos[j]++;
      }
    }
  }
  for (int i = 0; i < 3; i++) {
    int ind = best[i];
    cout << pr[ind].name << " " << pr[ind].v.size();
    for (int j = 0; j < pr[ind].v.size(); j++) cout << " " << pr[ind].v[j];
    cout << endl;
  }
  return 0;
}
