#include <bits/stdc++.h>

using namespace std;

struct order
{
  string name;
  string type;
  string comm;
  int    price;
};

typedef pair<int, int> Pi;
typedef pair<Pi, Pi> Ti;

int main()
{
  int n;
  while(cin >> n, n) {
    vector<order> orders(n);
    vector<bool> used(n, false);
    map<string, Ti> comms;
    map<string, Pi> dealers;
    for(int i = 0; i < n; i++) {
      string name, type, comm; int price;
      cin >> name >> type >> comm >> price;
      orders[i] = order{name, type, comm, price};
      if(dealers.count(name) == 0) dealers[name] = Pi(0, 0);
      order deal = order{"", "", "", (type == "SELL" ? -1 : 1010)};
      int idx = -1;
      for(int j = 0; j < i; j++) {
	if(used[j]) continue;
	if(orders[j].name == name) continue;	
	if(orders[j].type == type) continue;
	if(orders[j].comm != comm) continue;
	if(type == "SELL" && deal.price < orders[j].price ||
	   type == "BUY" && deal.price > orders[j].price) {
	  deal = orders[j];
	  idx = j;
	}
      }
      if(idx == -1) continue;
      int dlprice = (price + deal.price) / 2;
      if(type == "SELL") {
	if(price > deal.price) continue;
	dealers[deal.name].first += dlprice;
	dealers[name].second += dlprice;
      } else if(type == "BUY") {
	if(price < deal.price) continue;	
	dealers[name].first += dlprice;
	dealers[deal.name].second += dlprice;
      }
      if(comms.count(comm) == 0) comms[comm] = Ti(Pi(1010, -1), Pi(0, 0));
      comms[comm].first.first = min(comms[comm].first.first, dlprice);
      comms[comm].first.second = max(comms[comm].first.second, dlprice);
      comms[comm].second.first += dlprice;
      comms[comm].second.second++;
      used[i] = used[idx] = true;
    }
    for(auto c : comms) {
      cout << c.first << " ";
      cout << c.second.first.first << " ";
      cout << c.second.second.first / c.second.second.second << " ";
      cout << c.second.first.second << endl;
    }
    cout << "--" << endl;
    for(auto d : dealers) {
      cout << d.first << " ";
      cout << d.second.first << " ";
      cout << d.second.second << endl;
    }
    cout << "----------" << endl;
  }
  return 0;
}