#include <bits/stdc++.h>
using namespace std;
struct resident {
  string name, type, home;
  int idx, bonus;
  resident(int n1) {
    idx = n1;
    cin >> name >> type >> bonus >> home;
  }
};
struct item {
  string name, type;
  int atk, def, res;
  int size;
  item() { cin >> name >> type >> atk >> def >> res >> size; }
  int getScore(vector<resident> v) {
    int score = 0;
    if (type == "weapon")
      score = atk;
    else if (type == "armor")
      score = def;
    else
      score = res;
    for (int i = 0; i < v.size(); i++) {
      if (type == "weapon" && v[i].type == "gladiator")
        score += v[i].bonus;
      else if (type == "armor" && v[i].type == "sentry")
        score += v[i].bonus;
      else if (type == "orb" && v[i].type == "physician")
        score += v[i].bonus;
    }
    return score;
  }
  void show(vector<resident> v) {
    cout << name << " " << v.size();
    for (int i = 0; i < v.size(); i++) cout << " " << v[i].name;
    cout << endl;
  }
};
vector<item> items;
vector<resident> residents;
bool orden(int a, int b) { return residents[a].bonus > residents[b].bonus; }
int main() {
  int n, k;
  while (cin >> n) {
    items.clear();
    residents.clear();
    vector<int> W, A, O;
    int total = 0;
    map<string, int> itemIndex;
    for (int i = 0; i < n; i++) {
      items.push_back(item());
      if (items[i].type == "weapon")
        W.push_back(i);
      else if (items[i].type == "armor")
        A.push_back(i);
      else
        O.push_back(i);
      itemIndex[items[i].name] = i;
      total += items[i].size;
    }
    vector<vector<resident> > adj(n);
    cin >> k;
    vector<int> G, S, P;
    for (int i = 0; i < k; i++) {
      residents.push_back(resident(i));
      if (residents[i].type == "gladiator")
        G.push_back(i);
      else if (residents[i].type == "sentry")
        S.push_back(i);
      else
        P.push_back(i);
      adj[itemIndex[residents[i].home]].push_back(residents[i]);
    }
    if (total == k) {
      int wIndex = -1, aIndex = -1, oIndex = -1;
      int maxAtk = -1, maxDef = -1, maxRes = -1;
      for (int i = 0; i < W.size(); i++) {
        int atk = items[W[i]].getScore(adj[W[i]]);
        if (atk > maxAtk) {
          wIndex = W[i];
          maxAtk = atk;
        }
      }
      for (int j = 0; j < A.size(); j++) {
        int def = items[A[j]].getScore(adj[A[j]]);
        if (def > maxDef) {
          aIndex = A[j];
          maxDef = def;
        }
      }
      for (int k = 0; k < O.size(); k++) {
        int res = items[O[k]].getScore(adj[O[k]]);
        if (res > maxRes) {
          oIndex = O[k];
          maxRes = res;
        }
      }
      items[wIndex].show(adj[wIndex]);
      items[aIndex].show(adj[aIndex]);
      items[oIndex].show(adj[oIndex]);
    } else {
      sort(G.begin(), G.end(), orden);
      sort(S.begin(), S.end(), orden);
      sort(P.begin(), P.end(), orden);
      int wIndex = -1, aIndex = -1, oIndex = -1;
      int maxAtk = -1, maxDef = -1, maxRes = -1;
      vector<resident> g, s, p;
      for (int i = 0; i < W.size(); i++) {
        vector<resident> tmp;
        for (int j = 0; j < min((int)G.size(), items[W[i]].size); j++)
          tmp.push_back(residents[G[j]]);
        int score = items[W[i]].getScore(tmp);
        if (score > maxAtk) {
          wIndex = W[i];
          maxAtk = score;
          g = tmp;
        }
      }
      for (int i = 0; i < A.size(); i++) {
        vector<resident> tmp;
        for (int j = 0; j < min((int)S.size(), items[A[i]].size); j++)
          tmp.push_back(residents[S[j]]);
        int score = items[A[i]].getScore(tmp);
        if (score > maxDef) {
          aIndex = A[i];
          maxDef = score;
          s = tmp;
        }
      }
      for (int i = 0; i < O.size(); i++) {
        vector<resident> tmp;
        for (int j = 0; j < min((int)P.size(), items[O[i]].size); j++)
          tmp.push_back(residents[P[j]]);
        int score = items[O[i]].getScore(tmp);
        if (score > maxRes) {
          oIndex = O[i];
          maxRes = score;
          p = tmp;
        }
      }
      vector<bool> used(k, 0);
      for (int i = 0; i < g.size(); i++) used[g[i].idx] = 1;
      for (int i = 0; i < s.size(); i++) used[s[i].idx] = 1;
      for (int i = 0; i < p.size(); i++) used[p[i].idx] = 1;
      for (int i = 0; i < k; i++) {
        if (!used[i]) {
          if (items[wIndex].size > g.size())
            g.push_back(residents[i]);
          else if (items[aIndex].size > s.size())
            s.push_back(residents[i]);
          else if (items[oIndex].size > p.size())
            p.push_back(residents[i]);
        }
      }
      items[wIndex].show(g);
      items[aIndex].show(s);
      items[oIndex].show(p);
    }
  }
  return 0;
}
