#include <bits/stdc++.h>
using namespace std;
struct P {
  string name;
  vector<int> val;
  int sz;
  vector<string> resis;
};
struct Q {
  string name;
  vector<int> adder;
  string home;
  bool operator<(const Q &rhs) const { return adder < rhs.adder; }
};
vector<P> item[3];
vector<P> ites[3];
vector<Q> resk[3];
vector<int> make(int a, int b, int c) {
  vector<int> vi(3);
  vi[0] = a, vi[1] = b, vi[2] = c;
  return vi;
}
int main() {
  int N;
  while (cin >> N) {
    for (int j = 0; j < (int)(3); ++j) item[j].clear(), ites[j].clear();
    int szsum = 0;
    for (int i = 0; i < (int)(N); ++i) {
      string name, type;
      int a, d, r, s;
      cin >> name >> type >> a >> d >> r >> s;
      int j = -166;
      if (type == "weapon") j = 0;
      if (type == "armor") j = 1;
      if (type == "orb") j = 2;
      item[j].push_back((P){name, make(a, d, r), s});
      ites[j].push_back((P){name, make(a, d, r), s});
      szsum += s;
    }
    int M;
    cin >> M;
    for (int k = 0; k < (int)(3); ++k) resk[k].clear();
    for (int i = 0; i < (int)(M); ++i) {
      string name, type, home;
      int velo;
      cin >> name >> type >> velo >> home;
      int j = -166;
      if (type == "gladiator") j = 0;
      if (type == "sentry") j = 1;
      if (type == "physician") j = 2;
      vector<int> adder = make(0, 0, 0);
      adder[j] += velo;
      resk[j].push_back((Q){name, adder, home});
      for (int k = 0; k < (int)(3); ++k)
        for (__typeof((ites[k]).begin()) it = (ites[k]).begin();
             it != (ites[k]).end(); ++it)
          if (home == it->name) {
            for (int l = 0; l < (int)(3); ++l) it->val[l] += adder[l];
            it->resis.push_back(name);
          }
    }
    if (M == szsum) {
      vector<int> best = make(-1, -1, -1);
      for (int k = 0; k < (int)(3); ++k) {
        for (__typeof((ites[k]).begin()) it = (ites[k]).begin();
             it != (ites[k]).end(); ++it)
          best[k] = max(best[k], it->val[k]);
      }
      for (int k = 0; k < (int)(3); ++k) {
        for (__typeof((ites[k]).begin()) it = (ites[k]).begin();
             it != (ites[k]).end(); ++it)
          if (best[k] == it->val[k]) {
            vector<string> ret = it->resis;
            cout << (it->name) << " " << (int)((ret).size());
            for (__typeof((ret).begin()) vt = (ret).begin(); vt != (ret).end();
                 ++vt)
              cout << " " << (*vt);
            cout << endl;
            break;
          }
      }
    } else {
      for (int k = 0; k < (int)(3); ++k) {
        sort(resk[k].begin(), resk[k].end());
        reverse(resk[k].begin(), resk[k].end());
      }
      vector<int> best = make(-1, -1, -1);
      P ret[3];
      vector<string> vs[3];
      vector<string> remain[3];
      for (int k = 0; k < (int)(3); ++k) {
        for (__typeof((item[k]).begin()) it = (item[k]).begin();
             it != (item[k]).end(); ++it) {
          int u = it->val[k];
          vector<string> temp;
          for (int itr = 0; itr < (int)(it->sz); ++itr) {
            if (itr >= (int)((resk[k]).size())) break;
            u += resk[k][itr].adder[k];
            temp.push_back(resk[k][itr].name);
          }
          if (best[k] < u) {
            best[k] = u;
            vs[k] = temp;
            ret[k] = *it;
            remain[k].clear();
            for (int itr = (it->sz); itr < (int)((int)((resk[k]).size()));
                 ++itr)
              remain[k].push_back(resk[k][itr].name);
          }
        }
      }
      vector<string> rem;
      for (int k = 0; k < (int)(3); ++k)
        rem.insert(rem.end(), remain[k].begin(), remain[k].end());
      for (int k = 0; k < (int)(3); ++k) {
        while ((int)((vs[k]).size()) < ret[k].sz && (int)((rem).size())) {
          vs[k].push_back(rem.back());
          rem.pop_back();
        }
      }
      for (int k = 0; k < (int)(3); ++k) {
        cout << ret[k].name << " " << (int)((vs[k]).size());
        for (__typeof((vs[k]).begin()) vt = (vs[k]).begin();
             vt != (vs[k]).end(); ++vt)
          cout << " " << (*vt);
        cout << endl;
      }
    }
  }
}
