#include <stdio.h>
#include <iostream>
#include <vector>
#include <list>
#include <cmath>
#include <fstream>
#include <algorithm>
#include <string>
#include <queue>
#include <set>
#include <map>
#include <complex>
#include <iterator>
#include <cstdlib>
#include <cstring>
#include <sstream>

using namespace std;

#define EPS (1e-10)
#define EQ(a,b) (abs((a) - (b)) < EPS)
#define EQV(a,b) (EQ((a).real(),(b).real()) && EQ((a).imag(),(b).imag()))

typedef complex<double> P;
typedef long long ll;
const int INF=1000000000;

struct deal{
  string name;
  int val;
  string com;
  string kind;
};

struct ComInfo{
  int sum;
  int cnt;
  int low;
  int high;
};

struct DealerInfo{
  int paid;
  int received;
};

int main(){

  int n;
  while(cin>>n&&n!=0){
    map<string,ComInfo> ComInfos;
    map<string,DealerInfo> DealerInfos;
    map<string,vector<deal> > sds;
    map<string,vector<deal> > bds;
    for(int i = 0; i < n; i++){
      deal d;
      cin>>d.name>>d.kind>>d.com>>d.val;
      // ¤iÌo^
      if(ComInfos.find(d.com)==ComInfos.end()){
	ComInfo ci;
	ci.sum=ci.cnt=0;
	ci.low=INF;
	ci.high=-INF;
	ComInfos[d.com]=ci;
      }
      // æøÒÌo^
      if(DealerInfos.find(d.name)==DealerInfos.end()){
	DealerInfo di;
	di.paid=di.received=0;
	DealerInfos[d.name]=di;
      }
      // »Ý¶Ý·éàÌÅæøªÅ«é©`FbN
      if(d.kind=="BUY"){
	map<string,vector<deal> >::iterator it=sds.find(d.com);
	bool b=true;
	int minVal=INF;
	int idx=-1;
	// óâª¶Ý
	if(it!=sds.end()){
	  // XgðTõµAðð½·Åà¢àzðT·
	  for(int i = 0; i < it->second.size(); i++){
	    // Ã¢ûðKp·éÌÅAãÅ©Â©Á½¯¶valÌàÌÍ³
	    if(it->second[i].name!=d.name&&it->second[i].val<=d.val){
	      if(minVal>it->second[i].val){
		minVal=it->second[i].val;
		idx=i;
		b=false;
	      }
	    }
	  }
	}
	if(!b){
	  // æøª¬§
	  int val=d.val+it->second[idx].val;
	  val/=2;
	  DealerInfos[it->second[idx].name].received+=val;
	  DealerInfos[d.name].paid+=val;
	  ComInfos[it->first].sum+=val;
	  ComInfos[it->first].cnt++;
	  ComInfos[it->first].low=min(ComInfos[it->first].low,val);
	  ComInfos[it->first].high=max(ComInfos[it->first].high,val);
	  // vfÌí
	  it->second.erase(it->second.begin()+idx);
	}
	else{
	  if(bds.find(d.com)==bds.end())
	    bds[d.com]=vector<deal>();
	  bds[d.com].push_back(d);
	}
      }
      // è¶
      else{
	map<string,vector<deal> >::iterator it=bds.find(d.com);
	bool b=true;
	int maxVal=-INF;
	int idx=-1;
	// óâª¶Ý
	if(it!=bds.end()){
	  // XgðTõ
	  for(int i = 0; i < it->second.size(); i++){
	    // Ã¢ûðKp·éÌÅA©Â©Á½çbreak
	    if(it->second[i].name!=d.name&&it->second[i].val>=d.val){
	      if(maxVal<it->second[i].val){
		maxVal=it->second[i].val;
		idx=i;
		b=false;
	      }
	    }
	  }
	}
	if(!b){
	  // æøª¬§
	  int val=d.val+it->second[idx].val;
	  val/=2;
	  DealerInfos[it->second[idx].name].paid+=val;
	  DealerInfos[d.name].received+=val;
	  ComInfos[it->first].sum+=val;
	  ComInfos[it->first].cnt++;
	  ComInfos[it->first].low=min(ComInfos[it->first].low,val);
	  ComInfos[it->first].high=max(ComInfos[it->first].high,val);
	  b=false;
	  // vfÌí
	  it->second.erase(it->second.begin()+idx);
	}
	else{
	  if(sds.find(d.com)==sds.end())
	    sds[d.com]=vector<deal>();
	  sds[d.com].push_back(d);
	}
      }
    }
    vector<string> out1;
    for(map<string,ComInfo>::iterator it=ComInfos.begin();
	it!=ComInfos.end();it++){
      if(it->second.cnt==0)
	continue;
      cout<<it->first<<" ";
      cout<<it->second.low<<" ";
      cout<<it->second.sum/it->second.cnt<<" ";
      cout<<it->second.high<<endl;
    }
    cout<<"--"<<endl;
    for(map<string,DealerInfo>::iterator it=DealerInfos.begin();
	it!=DealerInfos.end();it++){
      cout<<it->first<<" ";
      cout<<it->second.paid<<" ";
      cout<<it->second.received<<endl;
    }
    cout<<"----------"<<endl;
  }

  return 0;
}

Measured memory_bytes: 0