#include <bits/stdc++.h>
using namespace std;
struct thing {
  string name;
  string type;
  int cap;
  int val;
  vector<pair<string, int> > residents;
  thing() {}
  thing(string n, string t, int s, int a, int d, int r) {
    name = n;
    type = t;
    cap = s;
    if (t == "weapon")
      val = a;
    else if (t == "armor")
      val = d;
    else
      val = r;
  }
};
map<string, thing> things;
thing choose(string type) {
  int mx = -1;
  for (map<string, thing>::iterator i = things.begin(); i != things.end(); ++i)
    if (i->second.type == type) {
      if (i->second.val > mx) mx = i->second.val;
    }
  for (map<string, thing>::iterator i = things.begin(); i != things.end(); ++i)
    if (i->second.type == type) {
      if (i->second.val == mx) return i->second;
    }
}
void update(string type, vector<pair<int, string> >& x) {
  for (map<string, thing>::iterator i = things.begin(); i != things.end(); ++i)
    if (i->second.type == type) {
      thing& t = i->second;
      t.residents.clear();
      for (int i = 0; i < t.cap && i < (int)x.size(); ++i) {
        t.val += x[i].first;
        t.residents.push_back(make_pair(x[i].second, x[i].first));
      }
    }
}
void print(thing t) {
  cout << t.name << " " << t.residents.size();
  for (int i = 0; i < (int)t.residents.size(); ++i)
    cout << " " << t.residents[i].first;
  cout << endl;
}
map<string, string> res_type;
void recalc() {
  for (map<string, thing>::iterator i = things.begin(); i != things.end();
       ++i) {
    thing& t = i->second;
    for (int j = 0; j < (int)t.residents.size(); ++j)
      if (res_type[t.residents[j].first] == t.type)
        t.val += t.residents[j].second;
  }
}
bool stuck() {
  for (map<string, thing>::iterator i = things.begin(); i != things.end();
       ++i) {
    if (i->second.cap != (int)i->second.residents.size()) return false;
  }
  return true;
}
vector<pair<int, string> > atk, def, res;
set<string> all;
int suma[1001];
int sumd[1001];
int sumr[1001];
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    string name, klass;
    int a, d, r, s;
    cin >> name >> klass >> a >> d >> r >> s;
    things[name] = thing(name, klass, s, a, d, r);
  }
  int m;
  cin >> m;
  for (int i = 0; i < m; ++i) {
    string name, home, klass;
    int b;
    cin >> name >> klass >> b >> home;
    if (klass == "gladiator") {
      atk.push_back(make_pair(b, name));
      res_type[name] = "weapon";
    } else if (klass == "sentry") {
      def.push_back(make_pair(b, name));
      res_type[name] = "armor";
    } else {
      res.push_back(make_pair(b, name));
      res_type[name] = "orb";
    }
    things[home].residents.push_back(make_pair(name, b));
    all.insert(name);
  }
  sort(atk.begin(), atk.end(), greater<pair<int, string> >());
  sort(def.begin(), def.end(), greater<pair<int, string> >());
  sort(res.begin(), res.end(), greater<pair<int, string> >());
  if (stuck()) {
    recalc();
    thing a = choose("weapon");
    thing d = choose("armor");
    thing r = choose("orb");
    print(a);
    print(d);
    print(r);
  } else {
    update("weapon", atk);
    update("armor", def);
    update("orb", res);
    thing a = choose("weapon");
    thing d = choose("armor");
    thing r = choose("orb");
    for (int i = 0; i < a.residents.size(); ++i)
      all.erase(a.residents[i].first);
    for (int i = 0; i < d.residents.size(); ++i)
      all.erase(d.residents[i].first);
    for (int i = 0; i < r.residents.size(); ++i)
      all.erase(r.residents[i].first);
    for (int i = a.residents.size(); i < a.cap && all.size(); ++i) {
      string s = *all.begin();
      a.residents.push_back(make_pair(s, 0));
      all.erase(s);
    }
    for (int i = d.residents.size(); i < d.cap && all.size(); ++i) {
      string s = *all.begin();
      d.residents.push_back(make_pair(s, 0));
      all.erase(s);
    }
    for (int i = r.residents.size(); i < r.cap && all.size(); ++i) {
      string s = *all.begin();
      r.residents.push_back(make_pair(s, 0));
      all.erase(s);
    }
    print(a);
    print(d);
    print(r);
  }
  return 0;
}
