#include <bits/stdc++.h>
using namespace std;
static const double EPS = 1e-9;
int ROUND(double x) { return (int)(x + 0.5); }
bool ISINT(double x) { return fabs(ROUND(x) - x) <= EPS; }
bool ISEQUAL(double x, double y) {
  return fabs(x - y) <= EPS * max(1.0, max(fabs(x), fabs(y)));
}
double SQSUM(double x, double y) { return x * x + y * y; }
template <class T>
bool INRANGE(T x, T a, T b) {
  return a <= x && x <= b;
}
enum ECLASS {
  ATK,
  DEF,
  RES,
  NUM_CLASS,
};
int main() {
  int N;
  scanf("%d ", &N);
  map<pair<int, string>, int> items[NUM_CLASS];
  map<string, int> items_simple[NUM_CLASS];
  int whole_size = 0;
  for (int i = 0; i < N; i++) {
    string name, clas;
    int atk, def, res, sz;
    cin >> name >> clas >> atk >> def >> res >> sz;
    ECLASS eclass;
    int tuyosa;
    if (clas == "weapon") {
      eclass = ATK;
      tuyosa = atk;
    } else if (clas == "armor") {
      eclass = DEF;
      tuyosa = def;
    } else if (clas == "orb") {
      eclass = RES;
      tuyosa = res;
    }
    items[eclass][make_pair(sz, name)] = tuyosa;
    items_simple[eclass][name] = tuyosa;
    whole_size += sz;
  }
  int K;
  scanf("%d ", &K);
  vector<pair<int, string> > yousei[NUM_CLASS];
  map<string, vector<string> > resi_info;
  set<string> unused_yousei_name;
  for (int i = 0; i < K; i++) {
    int bonus;
    string name, clas, item_name;
    cin >> name >> clas >> bonus >> item_name;
    ECLASS eclass;
    if (clas == "gladiator") {
      eclass = ATK;
    } else if (clas == "sentry") {
      eclass = DEF;
    } else if (clas == "physician") {
      eclass = RES;
    }
    yousei[eclass].push_back(make_pair(bonus, name));
    resi_info[item_name].push_back(name);
    unused_yousei_name.insert(name);
    if (items_simple[eclass].count(item_name)) {
      items_simple[eclass][item_name] += bonus;
    }
  }
  if (whole_size == K) {
    for (int i = 0; i < NUM_CLASS; i++) {
      string best_name;
      int best_tsuyosa = (-1);
      for (map<string, int>::iterator it = items_simple[i].begin();
           it != items_simple[i].end(); it++) {
        if (it->second > best_tsuyosa) {
          best_tsuyosa = it->second;
          best_name = it->first;
        }
      }
      printf("%s %d ", best_name.c_str(), ((int)resi_info[best_name].size()));
      for (int k = 0; k < ((int)resi_info[best_name].size()); k++) {
        printf("%s ", resi_info[best_name][k].c_str());
      }
      printf("\n");
    }
  } else {
    pair<int, string> best_name[NUM_CLASS];
    vector<string> best_youseis[NUM_CLASS];
    for (int i = 0; i < NUM_CLASS; i++) {
      sort(yousei[i].rbegin(), yousei[i].rend());
      int best_tsuyosa = (-1);
      int best_num_yousei = (-1);
      int now_size = 0;
      int now_sum_bonus = 0;
      for (map<pair<int, string>, int>::iterator it = items[i].begin();
           it != items[i].end(); it++) {
        while (it->first.first > now_size &&
               ((int)yousei[i].size()) > now_size) {
          now_sum_bonus += yousei[i][now_size].first;
          now_size++;
        }
        const int now_tsuyosa = it->second + now_sum_bonus;
        if (now_tsuyosa > best_tsuyosa) {
          best_tsuyosa = now_tsuyosa;
          best_name[i] = it->first;
          best_num_yousei = now_size;
        }
      }
      for (int k = 0; k < best_num_yousei; k++) {
        best_youseis[i].push_back(yousei[i][k].second);
        unused_yousei_name.erase(yousei[i][k].second);
      }
    }
    for (int i = 0; i < NUM_CLASS; i++) {
      while (((int)unused_yousei_name.size()) &&
             best_name[i].first > ((int)best_youseis[i].size())) {
        best_youseis[i].push_back(*unused_yousei_name.begin());
        unused_yousei_name.erase(unused_yousei_name.begin());
      }
      printf("%s %d ", best_name[i].second.c_str(),
             ((int)best_youseis[i].size()));
      for (int k = 0; k < ((int)best_youseis[i].size()); k++) {
        printf("%s ", best_youseis[i][k].c_str());
      }
      printf("\n");
    }
  }
}
