#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
using namespace std;

class P{
public:
	int price,id;
	string name,com;
	bool flg; //true:wü, false:p

	P(string _name,bool _flg,string _com,int _price,int _id){
		name = _name;
		flg = _flg;
		com = _com;
		price = _price;
		id = _id;
	}

	bool operator<(const P &p)const{
		if(price == p.price) return id < p.id;
		if(flg) return price > p.price;
		return price < p.price;
	}
};

typedef struct{int min,sum,max,n;}Com;
typedef struct{int pay,recv;}Dealer;

int main(void){
	int n;

	while(cin>>n,n){
		vector<P> buy,sell;
		map<string,Com> mc;
		map<string,Dealer> md;

		for(int i=0;i<n;i++){
			string name,flg,com;
			int price;
			cin>>name>>flg>>com>>price;

			md[name].pay += 0; //L[o^Ì½ß

			if(flg == "BUY"){
				bool buyFlg = false;
				for(int j=0;j<sell.size();j++){
					if(com == sell[j].com && name != sell[j].name && price >= sell[j].price){
						int deal = (price + sell[j].price) / 2;

						if(mc[com].min == 0){
							Com tmp = {deal,deal,deal,1};
							mc[com] = tmp;
						}
						else{
							if(mc[com].max < deal) mc[com].max = deal;
							if(mc[com].min > deal) mc[com].min = deal;
							mc[com].sum += deal;
							mc[com].n++;
						}

						md[name].pay += deal;
						md[sell[j].name].recv += deal;
						sell.erase(sell.begin()+j);
						buyFlg = true;
						break;
					}
				}

				if(!buyFlg){
					buy.push_back(P(name,true,com,price,i));
					sort(buy.begin(),buy.end());
				}
			}
			else{
				bool sellFlg = false;
				for(int j=0;j<buy.size();j++){
					if(com == buy[j].com && name != buy[j].name && buy[j].price >= price){
						int deal = (price + buy[j].price) / 2;

						if(mc[com].min == 0){
							Com tmp = {deal,deal,deal,1};
							mc[com] = tmp;
						}
						else{
							if(mc[com].max < deal) mc[com].max = deal;
							if(mc[com].min > deal) mc[com].min = deal;
							mc[com].sum += deal;
							mc[com].n++;
						}

						md[buy[j].name].pay += deal;
						md[name].recv += deal;
						buy.erase(buy.begin()+j);
						sellFlg = true;
						break;
					}
				}

				if(!sellFlg){
					sell.push_back(P(name,false,com,price,i));
					sort(sell.begin(),sell.end());
				}
			}

		}

		for(map<string,Com>::iterator i=mc.begin();i!=mc.end();i++){
			cout<<(i->first)<<" "<<(i->second).min<<" "<<(i->second).sum / (i->second).n<<" "<<(i->second).max<<endl;
		}
		cout<<"--\n";

		for(map<string,Dealer>::iterator i=md.begin();i!=md.end();i++){
			cout<<(i->first)<<" "<<(i->second).pay<<" "<<(i->second).recv<<endl;
		}
		cout<<"----------\n";
	}

	return 0;
}