#include <bits/stdc++.h>
using namespace std;
int main() {
  vector<pair<string, pair<int, int> > > weapon, armor, orb;
  int n, k;
  cin >> n;
  int sumsize = 0;
  for (int i = 0; i < n; ++i) {
    string name, clas;
    int atk, def, res, size;
    cin >> name >> clas >> atk >> def >> res >> size;
    if (clas == "weapon") {
      weapon.push_back(make_pair(name, make_pair(atk, size)));
    } else if (clas == "armor") {
      armor.push_back(make_pair(name, make_pair(def, size)));
    } else {
      orb.push_back(make_pair(name, make_pair(res, size)));
    }
    sumsize += size;
  }
  cin >> k;
  int sw = -1, sa = -1, so = -1;
  vector<string> a, b, c;
  if (k == sumsize) {
    map<string, int> gladiator, sentry, physician;
    map<string, vector<string> > residents;
    for (int i = 0; i < k; ++i) {
      string name, type, home;
      int bonus;
      cin >> name >> type >> bonus >> home;
      residents[home].push_back(name);
      if (type == "gladiator") {
        gladiator[home] += bonus;
      } else if (type == "sentry") {
        sentry[home] += bonus;
      } else {
        physician[home] += bonus;
      }
    }
    {
      int m = -1, q = -1;
      for (int i = 0; i < weapon.size(); ++i) {
        int p = weapon[i].second.first;
        p += gladiator[weapon[i].first];
        if (p > m) {
          m = p;
          q = i;
        }
      }
      sw = q;
    }
    {
      int m = -1, q = -1;
      for (int i = 0; i < armor.size(); ++i) {
        int p = armor[i].second.first;
        p += sentry[armor[i].first];
        if (p > m) {
          m = p;
          q = i;
        }
      }
      sa = q;
    }
    {
      int m = -1, q = -1;
      for (int i = 0; i < orb.size(); ++i) {
        int p = orb[i].second.first;
        p += physician[orb[i].first];
        if (p > m) {
          m = p;
          q = i;
        }
      }
      so = q;
    }
    a = residents[weapon[sw].first];
    b = residents[armor[sa].first];
    c = residents[orb[so].first];
  } else {
    vector<pair<int, string> > gladiator, sentry, physician;
    for (int i = 0; i < k; ++i) {
      string name, type, home;
      int bonus;
      cin >> name >> type >> bonus >> home;
      if (type == "gladiator") {
        gladiator.push_back(make_pair(bonus, name));
      } else if (type == "sentry") {
        sentry.push_back(make_pair(bonus, name));
      } else {
        physician.push_back(make_pair(bonus, name));
      }
    }
    sort(gladiator.rbegin(), gladiator.rend());
    sort(sentry.rbegin(), sentry.rend());
    sort(physician.rbegin(), physician.rend());
    {
      int m = -1, q = -1;
      for (int i = 0; i < weapon.size(); ++i) {
        int p = weapon[i].second.first;
        for (int j = 0; j < gladiator.size() && j < weapon[i].second.second;
             ++j) {
          p += gladiator[j].first;
        }
        if (p > m) {
          m = p;
          q = i;
        }
      }
      sw = q;
    }
    {
      int m = -1, q = -1;
      for (int i = 0; i < armor.size(); ++i) {
        int p = armor[i].second.first;
        for (int j = 0; j < sentry.size() && j < armor[i].second.second; ++j) {
          p += sentry[j].first;
        }
        if (p > m) {
          m = p;
          q = i;
        }
      }
      sa = q;
    }
    {
      int m = -1, q = -1;
      for (int i = 0; i < orb.size(); ++i) {
        int p = orb[i].second.first;
        for (int j = 0; j < physician.size() && j < orb[i].second.second; ++j) {
          p += physician[j].first;
        }
        if (p > m) {
          m = p;
          q = i;
        }
      }
      so = q;
    }
    vector<string> d;
    for (int j = 0; j < gladiator.size(); ++j) {
      if (j < weapon[sw].second.second) {
        a.push_back(gladiator[j].second);
      } else {
        d.push_back(gladiator[j].second);
      }
    }
    for (int j = 0; j < sentry.size(); ++j) {
      if (j < armor[sa].second.second) {
        b.push_back(sentry[j].second);
      } else {
        d.push_back(sentry[j].second);
      }
    }
    for (int j = 0; j < physician.size(); ++j) {
      if (j < orb[so].second.second) {
        c.push_back(physician[j].second);
      } else {
        d.push_back(physician[j].second);
      }
    }
    while (a.size() < weapon[sw].second.second && d.size()) {
      a.push_back(d.back());
      d.pop_back();
    }
    while (b.size() < armor[sa].second.second && d.size()) {
      b.push_back(d.back());
      d.pop_back();
    }
    while (c.size() < orb[so].second.second && d.size()) {
      c.push_back(d.back());
      d.pop_back();
    }
  }
  cout << weapon[sw].first << " " << a.size();
  for (int i = 0; i < a.size(); ++i) {
    cout << " " << a[i];
  }
  cout << endl;
  cout << armor[sa].first << " " << b.size();
  for (int i = 0; i < b.size(); ++i) {
    cout << " " << b[i];
  }
  cout << endl;
  cout << orb[so].first << " " << c.size();
  for (int i = 0; i < c.size(); ++i) {
    cout << " " << c[i];
  }
  cout << endl;
}
