#include <bits/stdc++.h>
using namespace std;
const int N = 110, K = 1010;
int n, k;
string item[N], resi[K], resi_home[K];
int type[N], para[N][3], size[N];
int resi_type[K], resi_bonus[K];
bool used[K];
int myfunc(const int &a, const pair<int, int> &b) { return a + b.first; }
int ans[3];
vector<int> ansv[3];
void iter(int ctrl) {
  vector<pair<int, int> > v;
  for (int i = 0; i < (int)(k); ++i) {
    if ((not used[i]) and resi_type[i] == ctrl) {
      v.push_back(make_pair(resi_bonus[i], i));
    }
  }
  sort(v.begin(), v.end(), greater<pair<int, int> >());
  int maxi = -1, maxi_id = -1;
  for (int i = 0; i < (int)(n); ++i) {
    if (type[i] == ctrl) {
      int sum = accumulate(v.begin(), v.begin() + min(size[i], (int)v.size()),
                           0, myfunc) +
                para[i][ctrl];
      if (maxi < sum) {
        maxi = sum;
        maxi_id = i;
      }
    }
  }
  int sz = min(size[maxi_id], (int)v.size());
  ans[ctrl] = maxi_id;
  for (int i = 0; i < sz; i++) {
    used[v[i].second] = true;
    ansv[ctrl].push_back(v[i].second);
  }
}
void iter2(int ctrl) {
  int maxi = -1, maxi_id = -1;
  for (int i = 0; i < (int)(n); ++i) {
    if (type[i] == ctrl) {
      int s = para[i][ctrl];
      for (int j = 0; j < (int)(k); ++j) {
        if (item[i] == resi_home[j] and resi_type[j] == ctrl) {
          s += resi_bonus[j];
        }
      }
      if (maxi < s) {
        maxi = s;
        maxi_id = i;
      }
    }
  }
  cout << item[maxi_id] << " " << size[maxi_id] << " ";
  for (int j = 0; j < (int)(k); ++j) {
    if (resi_home[j] == item[maxi_id]) {
      cout << resi[j] << " ";
    }
  }
  cout << endl;
}
int main() {
  int size_num = 0;
  cin >> n;
  for (int i = 0; i < (int)(n); ++i) {
    string types;
    cin >> item[i] >> types;
    if (types == "weapon") {
      type[i] = 0;
    } else if (types == "armor") {
      type[i] = 1;
    } else if (types == "orb") {
      type[i] = 2;
    } else {
      assert(false);
    }
    cin >> para[i][0] >> para[i][1] >> para[i][2] >> size[i];
    size_num += size[i];
  }
  cin >> k;
  for (int i = 0; i < (int)(k); ++i) {
    string types;
    cin >> resi[i] >> types;
    if (types == "gladiator") {
      resi_type[i] = 0;
    } else if (types == "sentry") {
      resi_type[i] = 1;
    } else if (types == "physician") {
      resi_type[i] = 2;
    } else {
      assert(false);
    }
    cin >> resi_bonus[i] >> resi_home[i];
  }
  if (size_num > k) {
    memset(used, false, sizeof(used));
    vector<pair<int, int> > v;
    iter(0);
    iter(1);
    iter(2);
    for (int i = 0; i < (int)(3); ++i) {
      int id = ans[i];
      while ((ansv[i].size() < size[id]) and
             ansv[0].size() + ansv[1].size() + ansv[2].size() < k) {
        for (int j = 0; j < (int)(k); ++j) {
          if (not used[j]) {
            ansv[i].push_back(j);
            used[j] = true;
            break;
          }
        }
      }
    }
    for (int i = 0; i < (int)(3); ++i) {
      int id = ans[i];
      cout << item[id] << " " << ansv[i].size() << " ";
      for (int j = 0; j < (int)(ansv[i].size()); ++j) {
        cout << resi[ansv[i][j]] << " ";
      }
      cout << endl;
    }
  } else {
    iter2(0);
    iter2(1);
    iter2(2);
  }
  return 0;
}
