#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline bool checkmax(T &a, const T &b) {
  return a < b ? a = b, 1 : 0;
}
map<string, int> wid, rid;
string wname[110], rname[1100];
int inc[1100], val[110], wtype[1100], rtype[1100], sz[1100], loc[1100],
    cnt[1100];
vector<int> item[3], res[3];
bool used[1100];
pair<int, int> best[3];
vector<int> ans[110];
inline int get_wtype(const string &s) {
  if (s == "weapon") return 0;
  if (s == "armor") return 1;
  return 2;
}
inline int get_rtype(const string &s) {
  if (s == "gladiator") return 0;
  if (s == "sentry") return 1;
  return 2;
}
inline bool cmp_val(const int &l, const int &r) { return val[l] > val[r]; }
inline bool cmp_inc(const int &l, const int &r) { return inc[l] > inc[r]; }
int main() {
  int N, M;
  cin >> N;
  for (int i = 0; i < (N); ++i) {
    string type;
    int atk, def, res;
    cin >> wname[i] >> type >> atk >> def >> res >> sz[i];
    wid[wname[i]] = i;
    int tmp;
    item[tmp = wtype[i] = get_wtype(type)].push_back(i);
    if (tmp == 0) {
      val[i] = atk;
    } else if (tmp == 1) {
      val[i] = def;
    } else {
      val[i] = res;
    }
  }
  cin >> M;
  for (int i = 0; i < (M); ++i) {
    string type, locname;
    cin >> rname[i] >> type >> inc[i] >> locname;
    loc[i] = wid[locname];
    cnt[loc[i]]++;
    res[rtype[i] = get_rtype(type)].push_back(i);
  }
  bool found = false;
  for (int i = 0; i < (N); ++i) {
    if (cnt[i] < sz[i]) {
      found = true;
      break;
    }
  }
  if (found) {
    for (int i = 0; i < (3); ++i) {
      sort(res[i].begin(), res[i].end(), cmp_inc);
    }
    for (int i = 0; i < (N); ++i) {
      ans[i].clear();
    }
    memset(used, false, sizeof(bool) * M);
    for (int type = 0; type < (3); ++type) {
      best[type] = make_pair((-1), (-1));
      for (int i = 0; i < (((int)(item[type].size()))); ++i) {
        int sum = val[item[type][i]];
        for (int j = 0; j < ((int)(res[type].size())) && j < sz[item[type][i]];
             ++j) {
          sum += inc[res[type][j]];
        }
        checkmax(best[type], make_pair((sum), (item[type][i])));
      }
      for (int j = 0;
           j < ((int)(res[type].size())) && j < sz[best[type].second]; ++j) {
        ans[best[type].second].push_back(res[type][j]);
        used[res[type][j]] = true;
      }
    }
    for (int i = 0; i < (M); ++i) {
      if (!used[i]) {
        for (int j = 0; j < (N); ++j) {
          if (((int)(ans[j].size())) < sz[j]) {
            ans[j].push_back(i);
            break;
          }
        }
      }
    }
    for (int i = 0; i < (3); ++i) {
      cout << wname[best[i].second] << " "
           << ((int)(ans[best[i].second].size()));
      for (int j = 0; j < (((int)(ans[best[i].second].size()))); ++j) {
        cout << " " << rname[ans[best[i].second][j]];
      }
      cout << endl;
    }
  } else {
    for (int i = 0; i < (3); ++i) {
      for (int j = 0; j < (((int)(res[i].size()))); ++j) {
        if (wtype[loc[res[i][j]]] == i) {
          val[loc[res[i][j]]] += inc[res[i][j]];
        }
      }
    }
    for (int type = 0; type < (3); ++type) {
      sort(item[type].begin(), item[type].end(), cmp_val);
      cout << wname[item[type][0]] << " " << cnt[item[type][0]];
      for (int i = 0; i < (3); ++i) {
        for (int j = 0; j < (((int)(res[i].size()))); ++j) {
          if (loc[res[i][j]] == item[type][0]) cout << " " << rname[res[i][j]];
        }
      }
      cout << endl;
    }
  }
  return 0;
}
