#include <bits/stdc++.h>
using namespace std;
struct Item {
  string name;
  int value;
  int size;
  Item() {}
  Item(string name, int value, int size)
      : name(name), value(value), size(size) {}
};
struct Resident {
  string name;
  string home;
  string type;
  int bonus;
  bool used;
  Resident() {}
  Resident(string name, string home, string type, int bonus)
      : name(name), home(home), type(type), bonus(bonus) {
    used = false;
  }
  bool operator<(const Resident &ot) const { return bonus > ot.bonus; }
};
vector<Item> weapons, armors, orbs;
vector<Resident> residents, weaponResidents, armorResidents, orbResidents;
int n, k;
int totalSize;
int usedSize;
Item getBest(vector<Item> &items, vector<Resident> &rr, string type) {
  int ibest = -1;
  int bestValue;
  if (totalSize != k) {
    for (int i = 0; i < items.size(); i++) {
      int value = items[i].value;
      int limite = items[i].size;
      for (int j = 0; j < residents.size() && limite > 0; j++) {
        if (residents[j].type == type) {
          value += residents[j].bonus;
          limite--;
        }
      }
      if (ibest == -1 || bestValue < value) {
        bestValue = value;
        ibest = i;
      }
    }
    int limite = items[ibest].size;
    for (int j = 0; j < residents.size() && limite > 0; j++) {
      if (residents[j].type == type) {
        rr.push_back(residents[j]);
        residents[j].used = true;
        limite--;
      }
    }
  } else {
    for (int i = 0; i < items.size(); i++) {
      int value = items[i].value;
      for (int j = 0; j < residents.size(); j++) {
        if (residents[j].home == items[i].name && residents[j].type == type) {
          value += residents[j].bonus;
        }
      }
      if (ibest == -1 || bestValue < value) {
        bestValue = value;
        ibest = i;
      }
    }
    for (int j = 0; j < residents.size(); j++) {
      if (residents[j].home == items[ibest].name) {
        rr.push_back(residents[j]);
        residents[j].used = true;
      }
    }
  }
  return items[ibest];
}
int main() {
  scanf("%d", &n);
  totalSize = 0;
  usedSize = 0;
  for (int i = 0; i < n; i++) {
    char name[12], classe[12];
    int atk, def, orbVal;
    int size;
    scanf("%s%s%d%d%d%d", name, classe, &atk, &def, &orbVal, &size);
    if (classe[0] == 'w') {
      weapons.push_back(Item(string(name), atk, size));
    } else if (classe[0] == 'a') {
      armors.push_back(Item(string(name), def, size));
    } else {
      orbs.push_back(Item(string(name), orbVal, size));
    }
    totalSize += size;
  }
  scanf("%d", &k);
  for (int i = 0; i < k; i++) {
    char name[12], type[12], home[12];
    int bonus;
    scanf("%s%s%d%s", name, type, &bonus, home);
    residents.push_back(
        Resident(string(name), string(home), string(type), bonus));
  }
  Item weapon, armor, orb;
  sort(residents.begin(), residents.end());
  weapon = getBest(weapons, weaponResidents, string("gladiator"));
  armor = getBest(armors, armorResidents, string("sentry"));
  orb = getBest(orbs, orbResidents, string("physician"));
  if (totalSize != k) {
    int usedRes =
        weaponResidents.size() + armorResidents.size() + orbResidents.size();
    int usedSlots = weapon.size + armor.size + orb.size;
    if (k - usedRes > totalSize - usedSlots) {
      int adicionais = (k - usedRes) - (totalSize - usedSlots);
      for (int i = 0; i < residents.size() && adicionais > 0 &&
                      weaponResidents.size() < weapon.size;
           i++) {
        if (!residents[i].used) {
          residents[i].used = true;
          weaponResidents.push_back(residents[i]);
          adicionais--;
        }
      }
      for (int i = 0; i < residents.size() && adicionais > 0 &&
                      armorResidents.size() < armor.size;
           i++) {
        if (!residents[i].used) {
          residents[i].used = true;
          armorResidents.push_back(residents[i]);
          adicionais--;
        }
      }
      for (int i = 0; i < residents.size() && adicionais > 0 &&
                      orbResidents.size() < orb.size;
           i++) {
        if (!residents[i].used) {
          residents[i].used = true;
          orbResidents.push_back(residents[i]);
          adicionais--;
        }
      }
    }
  }
  printf("%s ", weapon.name.c_str());
  printf("%d", weaponResidents.size());
  for (int i = 0; i < weaponResidents.size(); i++) {
    printf(" %s", weaponResidents[i].name.c_str());
  }
  printf("\n");
  printf("%s ", armor.name.c_str());
  printf("%d", armorResidents.size());
  for (int i = 0; i < armorResidents.size(); i++) {
    printf(" %s", armorResidents[i].name.c_str());
  }
  printf("\n");
  printf("%s ", orb.name.c_str());
  printf("%d", orbResidents.size());
  for (int i = 0; i < orbResidents.size(); i++) {
    printf(" %s", orbResidents[i].name.c_str());
  }
  printf("\n");
  return 0;
}
