#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, m, sum = 0;
  cin >> n;
  vector<string> RES[3][100];
  vector<pair<string, pair<long long, long long> > > eq[3];
  vector<pair<long long, string> > res[3];
  map<string, int> mp;
  mp["weapon"] = 0;
  mp["armor"] = 1;
  mp["orb"] = 2;
  mp["gladiator"] = 0;
  mp["sentry"] = 1;
  mp["physician"] = 2;
  for (long long i = 0; i < ((long long)n); i++) {
    string name, type;
    long long a[3], num;
    cin >> name >> type >> a[0] >> a[1] >> a[2] >> num;
    sum += num;
    eq[mp[type]].push_back(make_pair(name, make_pair(a[mp[type]], num)));
  }
  cin >> m;
  if (sum == m) {
    for (long long i = 0; i < ((long long)m); i++) {
      string name, type, owner;
      long long power;
      cin >> name >> type >> power >> owner;
      for (long long j = 0; j < ((long long)3); j++)
        for (long long k = 0; k < ((long long)((long long)(eq[j]).size())); k++)
          if (eq[j][k].first == owner) {
            RES[j][k].push_back(name);
            if (mp[type] == j) eq[j][k].second.first += power;
          }
    }
    for (long long i = 0; i < ((long long)3); i++) {
      long long best = 0;
      for (long long j = 0; j < ((long long)((long long)(eq[i]).size())); j++)
        if (eq[i][best].second.first < eq[i][j].second.first) best = j;
      cout << eq[i][best].first << " " << ((long long)(RES[i][best]).size())
           << " ";
      for (long long j = 0; j < ((long long)((long long)(RES[i][best]).size()));
           j++)
        cout << RES[i][best][j] << " ";
      cout << endl;
    }
  } else {
    vector<string> names;
    bool used[1005];
    for (long long i = 0; i < ((long long)1005); i++) used[i] = false;
    for (long long i = 0; i < ((long long)m); i++) {
      string name, type, owner;
      long long power;
      cin >> name >> type >> power >> owner;
      res[mp[type]].push_back(make_pair(power, name));
      names.push_back(name);
    }
    for (long long i = 0; i < ((long long)3); i++)
      sort(res[i].begin(), res[i].end());
    for (long long i = 0; i < ((long long)3); i++)
      reverse(res[i].begin(), res[i].end());
    for (long long i = 0; i < ((long long)3); i++) {
      long long best = 0;
      for (long long j = 0; j < ((long long)((long long)(eq[i]).size())); j++) {
        long long sum0 = eq[i][best].second.first;
        for (long long k = 0; k < ((long long)min(((long long)(res[i]).size()),
                                                  eq[i][best].second.second));
             k++)
          sum0 += res[i][k].first;
        long long sum1 = eq[i][j].second.first;
        for (long long k = 0; k < ((long long)min(((long long)(res[i]).size()),
                                                  eq[i][j].second.second));
             k++)
          sum1 += res[i][k].first;
        if (sum0 < sum1) best = j;
      }
      for (long long j = 0; j < ((long long)min(((long long)(res[i]).size()),
                                                eq[i][best].second.second));
           j++) {
        for (long long k = 0; k < ((long long)m); k++)
          if (res[i][j].second == names[k]) used[k] = true;
      }
    }
    for (long long i = 0; i < ((long long)3); i++) {
      long long best = 0;
      for (long long j = 0; j < ((long long)((long long)(eq[i]).size())); j++) {
        long long sum0 = eq[i][best].second.first;
        for (long long k = 0; k < ((long long)min(((long long)(res[i]).size()),
                                                  eq[i][best].second.second));
             k++)
          sum0 += res[i][k].first;
        long long sum1 = eq[i][j].second.first;
        for (long long k = 0; k < ((long long)min(((long long)(res[i]).size()),
                                                  eq[i][j].second.second));
             k++)
          sum1 += res[i][k].first;
        if (sum0 < sum1) best = j;
      }
      vector<string> ans;
      cout << eq[i][best].first << " ";
      for (long long j = 0; j < ((long long)min(((long long)(res[i]).size()),
                                                eq[i][best].second.second));
           j++)
        ans.push_back(res[i][j].second);
      for (long long j = 0; j < ((long long)eq[i][best].second.second -
                                 ((long long)(res[i]).size()));
           j++) {
        for (long long k = 0; k < ((long long)m); k++)
          if (!used[k]) {
            ans.push_back(names[k]);
            used[k] = true;
            break;
          }
      }
      cout << ((long long)(ans).size()) << " ";
      for (long long j = 0; j < ((long long)((long long)(ans).size())); j++)
        cout << ans[j] << " ";
      cout << endl;
    }
  }
}
