#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
const ld eps = 1e-9;
const ld pi=acos(-1.0);

struct order {
	string player_name;
	bool buy;
	string item_name;
	int price;
};

bool operator==(const order&l, const order&r) {
	return l.player_name==r.player_name&&
		l.buy==r.buy&&
		l.item_name==r.item_name&&
		l.price==r.price;
}

bool match(order&l, order&r) {
	if(l.player_name==r.player_name)return false;
	if(l.item_name!=r.item_name)return false;

	if (l.buy) {
		if(r.buy)return false;
		return l.price>=r.price;
	}
	else {
		if(!r.buy)return false;
		return l.price<=r.price;
	}
}

int main() {

	while (true) {
		int N;cin>>N;
		if(!N)break;

		vector<order>buy_col,sell_col;

		map<string ,vector<int>>item_deals;
		map<string,pair<int,int>>player_moneys;
		for (int i = 0; i < N; ++i) {
			string player_name,buy_st,item_name ;int price;
			cin>>player_name>>buy_st>>item_name>>price;
			player_moneys[player_name];
			bool buy=buy_st=="BUY";
			order adata{ player_name,buy,item_name,price };

			bool valid=false;
			order opdata;
			if (buy) {
				for (auto s : sell_col) {
					if (match(s, adata)) {
						if (!valid) {
							valid=true;
							opdata=s;
						}
						else {
							if (opdata.price > s.price) {
								opdata=s;
							}
						}
					}
				}
			}
			else {
				for (auto b : buy_col) {
					if (match(b, adata)) {
						if (!valid) {
							valid = true;
							opdata = b;
						}
						else {
							if (opdata.price < b.price) {
								opdata = b;
							}
						}
					}
				}
			}
			if (valid) {
				int deal_money=(adata.price+opdata.price)/2;
				item_deals[adata.item_name].push_back(deal_money);
				if (buy) {
					sell_col.erase(find(sell_col.begin(), sell_col.end(), opdata));

					player_moneys[adata.player_name].second +=deal_money;
					player_moneys[opdata.player_name].first +=deal_money;
				}
				else {
					buy_col.erase(find(buy_col.begin(), buy_col.end(), opdata));

					player_moneys[adata.player_name].first +=deal_money;
					player_moneys[opdata.player_name].second +=deal_money;
				}
			}
			else {
				if(buy)buy_col.push_back(adata);
				else sell_col.push_back(adata);
			}
		}

		{
			for (auto id : item_deals) {
				string item_name=id.first;
				int item_min_money=*min_element(id.second.begin(),id.second.end());
				int item_ave_money=accumulate(id.second.begin(),id.second.end(),0)/id.second.size();
				int item_max_money=*max_element(id.second.begin(),id.second.end());
				cout<<item_name<<" "<<item_min_money<<" "<<item_ave_money<<" "<<item_max_money<<endl;
			}

		}
		cout<<"--"<<endl;
		{
			for (auto pm : player_moneys) {
				string player_name=pm.first;
				int pay_money = pm.second.first;
				int use_money=pm.second.second;

				cout<<player_name<<" "<<use_money<<" "<<pay_money<<endl;
			}
		}
		cout<<"----------"<<endl;
	}
	

	return 0;
}
