#include <bits/stdc++.h>
using namespace std;
struct Resident {
  string name, type, home;
  int bonus;
  bool operator<(const Resident &o) const { return bonus > o.bonus; }
};
struct Item {
  string name, type;
  int atk, def, res, size;
  vector<Resident> residents;
  Item() { atk = def = res = -100000000; }
  int get_atk() const {
    int ret = atk;
    for (int i = 0; i < ((int)residents.size()); ++i) {
      if (residents[i].type[0] == 'g') {
        ret += residents[i].bonus;
      }
    }
    return ret;
  }
  int get_def() const {
    int ret = def;
    for (int i = 0; i < ((int)residents.size()); ++i) {
      if (residents[i].type[0] == 's') {
        ret += residents[i].bonus;
      }
    }
    return ret;
  }
  int get_res() const {
    int ret = res;
    for (int i = 0; i < ((int)residents.size()); ++i) {
      if (residents[i].type[0] == 'p') {
        ret += residents[i].bonus;
      }
    }
    return ret;
  }
};
vector<Resident> atk, def, res;
vector<Item> weapon, armor, orb;
int n, m;
void output(Item i) {
  cout << i.name << ' ' << ((int)i.residents.size());
  for (int j = 0; j < ((int)i.residents.size()); ++j) {
    cout << ' ' << i.residents[j].name;
  }
  cout << endl;
}
int main() {
  int tot_size = 0;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    Item cur;
    cin >> cur.name >> cur.type;
    cin >> cur.atk >> cur.def >> cur.res;
    cin >> cur.size;
    tot_size += cur.size;
    if (cur.type == "weapon") {
      weapon.push_back(cur);
    } else if (cur.type == "armor") {
      armor.push_back(cur);
    } else if (cur.type == "orb") {
      orb.push_back(cur);
    }
  }
  cin >> m;
  for (int i = 0; i < m; ++i) {
    Resident cur;
    cin >> cur.name >> cur.type >> cur.bonus >> cur.home;
    for (int j = 0; j < ((int)weapon.size()); ++j) {
      if (weapon[j].name == cur.home) {
        weapon[j].residents.push_back(cur);
      }
    }
    for (int j = 0; j < ((int)armor.size()); ++j) {
      if (armor[j].name == cur.home) {
        armor[j].residents.push_back(cur);
      }
    }
    for (int j = 0; j < ((int)orb.size()); ++j) {
      if (orb[j].name == cur.home) {
        orb[j].residents.push_back(cur);
      }
    }
    if (cur.type == "gladiator") {
      atk.push_back(cur);
    } else if (cur.type == "sentry") {
      def.push_back(cur);
    } else if (cur.type == "physician") {
      res.push_back(cur);
    }
  }
  sort(atk.begin(), atk.end());
  sort(def.begin(), def.end());
  sort(res.begin(), res.end());
  bool has_space = tot_size > m;
  if (has_space) {
    for (int i = 0; i < ((int)weapon.size()); ++i) {
      weapon[i].residents.clear();
      for (int j = 0; j < weapon[i].size && j < ((int)atk.size()); ++j) {
        weapon[i].residents.push_back(atk[j]);
      }
    }
    for (int i = 0; i < ((int)armor.size()); ++i) {
      armor[i].residents.clear();
      for (int j = 0; j < armor[i].size && j < ((int)def.size()); ++j) {
        armor[i].residents.push_back(def[j]);
      }
    }
    for (int i = 0; i < ((int)orb.size()); ++i) {
      orb[i].residents.clear();
      for (int j = 0; j < orb[i].size && j < ((int)res.size()); ++j) {
        orb[i].residents.push_back(res[j]);
      }
    }
  }
  Item best_weapon = weapon[0];
  for (int i = 0; i < ((int)weapon.size()); ++i) {
    if (weapon[i].get_atk() > best_weapon.get_atk()) {
      best_weapon = weapon[i];
    }
  }
  Item best_armor = armor[0];
  for (int i = 0; i < ((int)armor.size()); ++i) {
    if (armor[i].get_def() > best_armor.get_def()) {
      best_armor = armor[i];
    }
  }
  Item best_orb = orb[0];
  for (int i = 0; i < ((int)orb.size()); ++i) {
    if (orb[i].get_res() > best_orb.get_res()) {
      best_orb = orb[i];
    }
  }
  if (has_space) {
    Item item[3] = {best_weapon, best_armor, best_orb};
    vector<Resident> all(atk.begin(), atk.end());
    all.insert(all.end(), def.begin(), def.end());
    all.insert(all.end(), res.begin(), res.end());
    set<string> exist;
    for (int i = 0; i < 3; ++i) {
      for (int j = 0; j < ((int)item[i].residents.size()); ++j) {
        exist.insert(item[i].residents[j].name);
      }
    }
    for (int i = 0; i < ((int)all.size()); ++i) {
      if (exist.count(all[i].name)) {
        continue;
      }
      for (int j = 0; j < 3; ++j) {
        if (((int)item[j].residents.size()) < item[j].size) {
          item[j].residents.push_back(all[i]);
          break;
        }
      }
    }
    best_weapon = item[0];
    best_armor = item[1];
    best_orb = item[2];
  }
  output(best_weapon);
  output(best_armor);
  output(best_orb);
  return 0;
}
