#include <bits/stdc++.h>
using namespace std;
void require(bool cond, const string& message = "Runtime error") {
  if (!cond) {
    cerr << message << endl;
    assert(false);
  }
}
void readData() {}
struct Item {
  string name;
  int val, size;
};
struct Resident {
  string name;
  int bonus;
};
bool operator<(const Resident& a, const Resident& b) {
  return a.bonus > b.bonus;
}
int pack(const Item& item, const vector<Resident>& rss) {
  int res = item.val;
  for (int i = 0; i < int(min(item.size, (int)rss.size())); ++i) {
    res += rss[i].bonus;
  }
  return res;
}
void solve() {
  int n;
  cin >> n;
  map<string, vector<Item> > items;
  map<string, int> cnt;
  map<string, int> add;
  map<string, string> clz;
  map<string, vector<Resident> > homes;
  for (int i = 0; i < int(n); ++i) {
    string name, clazz;
    int atk, def, res, size;
    cin >> name >> clazz >> atk >> def >> res >> size;
    Item item = {name, atk, size};
    if (clazz == "armor") {
      item.val = def;
    } else if (clazz == "orb") {
      item.val = res;
    } else {
      assert(clazz == "weapon");
    }
    items[clazz].push_back(item);
    clz[name] = clazz;
  }
  set<string> allres;
  int k;
  cin >> k;
  map<string, vector<Resident> > ress;
  for (int i = 0; i < int(k); ++i) {
    string name, clazz, home;
    int bonus;
    cin >> name >> clazz >> bonus >> home;
    ++cnt[home];
    string cl = clazz;
    if (cl == "gladiator")
      clazz = "weapon";
    else if (cl == "sentry")
      clazz = "armor";
    else if (cl == "physician")
      clazz = "orb";
    else {
      assert(false);
    }
    allres.insert(name);
    Resident res = {name, bonus};
    ress[clazz].push_back(res);
    homes[home].push_back(res);
    if (clz[home] == clazz) {
      add[home] += bonus;
    }
  }
  bool full = true;
  for (map<string, vector<Item> >::iterator it = items.begin();
       it != items.end(); ++it) {
    const vector<Item>& its = it->second;
    for (int i = 0; i < int(its.size()); ++i) {
      const Item& item = its[i];
      if (cnt[item.name] < item.size) {
        full = false;
        break;
      }
    }
    if (!full) {
      break;
    }
  }
  vector<string> cnames;
  cnames.push_back("weapon");
  cnames.push_back("armor");
  cnames.push_back("orb");
  if (full) {
    for (int it = 0; it < int(cnames.size()); ++it) {
      string clazz = cnames[it];
      const vector<Item>& its = items[clazz];
      Item nb = its[0];
      for (int i = 0; i < int(its.size()); ++i) {
        const Item& item = its[i];
        if (item.val + add[item.name] > nb.val + add[nb.name]) nb = item;
      }
      cout << nb.name << " " << homes[nb.name].size();
      const vector<Resident>& rss = homes[nb.name];
      for (int i = 0; i < int(rss.size()); ++i) cout << " " << rss[i].name;
      cout << endl;
    }
    return;
  }
  for (int it = 0; it < int(cnames.size()); ++it) {
    sort(ress[cnames[it]].begin(), ress[cnames[it]].end());
  }
  map<string, Item> best;
  map<string, vector<string> > bres;
  for (int it = 0; it < int(cnames.size()); ++it) {
    string clazz = cnames[it];
    vector<Item>& its = items[clazz];
    int maxi = 0;
    int maxv = -1;
    const vector<Resident>& rs = ress[clazz];
    for (int i = 0; i < int(its.size()); ++i) {
      const Item& item = its[i];
      int pk = pack(item, rs);
      if (pk > maxv) {
        maxv = pk;
        maxi = i;
      }
    }
    Item item = its[maxi];
    best[clazz] = item;
    vector<string> ans;
    for (int i = 0; i < int(min(item.size, (int)rs.size())); ++i) {
      item.val += rs[i].bonus;
      ans.push_back(rs[i].name);
      allres.erase(rs[i].name);
    }
    bres[clazz] = ans;
  }
  queue<string> left;
  for (set<string>::iterator it = allres.begin(); it != allres.end(); ++it) {
    left.push(*it);
  }
  for (int it = 0; it < int(cnames.size()); ++it) {
    string clazz = cnames[it];
    while (!left.empty() && bres[clazz].size() < best[clazz].size) {
      bres[clazz].push_back(left.front());
      left.pop();
    }
  }
  for (int it = 0; it < int(cnames.size()); ++it) {
    string clazz = cnames[it];
    const vector<string>& rss = bres[clazz];
    cout << best[clazz].name << " " << rss.size();
    for (int i = 0; i < int(rss.size()); ++i) cout << " " << rss[i];
    cout << endl;
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  readData();
  solve();
  return 0;
}
