#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <iostream>
#include <set>
#include <map>
#include <time.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;

enum Type{
	SELL,
	BUY,
};

struct Info{
	Type type;
	int person,item_name,price;
	bool erased;
};

bool strCmp(char* base, char* comp){
	int length1,length2;
	for(length1=0;base[length1] != '\0';length1++);
	for(length2=0;comp[length2] != '\0';length2++);
	if(length1 != length2)return false;

	for(int i=0;base[i] != '\0'; i++){
		if(base[i] != comp[i])return false;
	}
	return true;
}

void strcpy(char* to,char* str){
	for(int i=0;str[i] != '\0';i++){
		to[i] = str[i];
		to[i+1] = '\0';
	}
}

struct Item{
	int min_price,max_price,deal_sum,deal_num;
};

struct Dealer{
	bool operator<(const struct Dealer &arg) const{
		int i;
		for(i=0;name[i] != '\0' && arg.name[i] != '\0'; i++){
			if(name[i] != arg.name[i]){
				if(name[i] < arg.name[i])return true;
				else{
					return false;
				}
			}
		}
		if(name[i] == '\0')return true;
		else{
			return false;
		}
	}
	char name[11];
	int paid,received;
};

int N;
Item item[26];
Dealer dealer[1000];
char buf[50];

vector<Info> SELL_INFO,BUY_INFO;

void func(){

	for(int i = 0; i < 26; i++){
		item[i].min_price = BIG_NUM;
		item[i].max_price = -BIG_NUM;
		item[i].deal_sum = 0;
		item[i].deal_num = 0;
	}

	for(int i = 0; i < N; i++){
		dealer[i].paid = 0;
		dealer[i].received = 0;
	}

	SELL_INFO.clear();
	BUY_INFO.clear();

	getchar();

	int index;
	char work[11];

	int dealer_index = 0;
	int tmp,minimum,maximum,tmp_index,deal_price;

	for(int i = 0; i < N; i++){
		fgets(buf,50,stdin);

		Info new_info;
		new_info.person = -1;

		for(index = 0; buf[index] != ' '; index++){
			work[index] = buf[index];
		}
		work[index] = '\0';

		for(int k = 0; k < dealer_index; k++){
			if(strCmp(dealer[k].name,work)){
				new_info.person = k;
				break;
			}
		}
		if(new_info.person == -1){
			strcpy(dealer[dealer_index].name,work);
			new_info.person = dealer_index;
			dealer_index++;
		}

		index++;
		if(buf[index] == 'B'){
			new_info.type = BUY;
			index += 4;
		}else{
			new_info.type = SELL;
			index += 5;
		}

		new_info.item_name = buf[index]-'A';

		index += 2;
		tmp = 0;

		for(;buf[index] >= '0' && buf[index] <= '9'; index++){
			tmp = 10*tmp + buf[index]-'0';
		}
		new_info.price = tmp;
		new_info.erased = false;

		if(new_info.type == BUY){
			minimum = BIG_NUM;

			for(int k = 0; k < SELL_INFO.size(); k++){
				if(SELL_INFO[k].erased == true || SELL_INFO[k].person == new_info.person)continue;

				if(SELL_INFO[k].item_name == new_info.item_name && SELL_INFO[k].price <= new_info.price){
					if(minimum > SELL_INFO[k].price){
						minimum = SELL_INFO[k].price;
						tmp_index = k;
					}
				}
			}

			if(minimum == BIG_NUM){
				BUY_INFO.push_back(new_info);
			}else{
				deal_price = (SELL_INFO[tmp_index].price+new_info.price)/2;

				SELL_INFO[tmp_index].erased = true;

				item[new_info.item_name].deal_num++;
				item[new_info.item_name].deal_sum+= deal_price;
				item[new_info.item_name].min_price = min(item[new_info.item_name].min_price,deal_price);
				item[new_info.item_name].max_price = max(item[new_info.item_name].max_price,deal_price);

				dealer[new_info.person].paid += deal_price;
				dealer[SELL_INFO[tmp_index].person].received += deal_price;

			}

		}else{ //new_info.type == SELL
			maximum = -BIG_NUM;

			for(int k = 0; k < BUY_INFO.size(); k++){
				if(BUY_INFO[k].erased == true || BUY_INFO[k].person == new_info.person)continue;

				if(BUY_INFO[k].item_name == new_info.item_name && BUY_INFO[k].price >= new_info.price){
					if(maximum < BUY_INFO[k].price){
						maximum = BUY_INFO[k].price;
						tmp_index = k;
					}
				}
			}

			if(maximum == -BIG_NUM){
				SELL_INFO.push_back(new_info);
			}else{
				deal_price = (BUY_INFO[tmp_index].price+new_info.price)/2;

				BUY_INFO[tmp_index].erased = true;

				item[new_info.item_name].deal_num++;
				item[new_info.item_name].deal_sum+= deal_price;
				item[new_info.item_name].min_price = min(item[new_info.item_name].min_price,deal_price);
				item[new_info.item_name].max_price = max(item[new_info.item_name].max_price,deal_price);

				dealer[new_info.person].received += deal_price;
				dealer[BUY_INFO[tmp_index].person].paid += deal_price;

			}
		}

	}

	for(int i = 0; i < 26; i++){
		if(item[i].deal_num > 0){
			printf("%c %d %d %d\n",'A'+i,item[i].min_price,item[i].deal_sum/item[i].deal_num,item[i].max_price);
		}
	}
	printf("--\n");
	sort(dealer,dealer+dealer_index);
	for(int i = 0; i < dealer_index; i++){
		printf("%s %d %d\n",dealer[i].name,dealer[i].paid,dealer[i].received);
	}
	printf("----------\n");
}


int main(){

	while(true){
		scanf("%d",&N);
		if(N == 0)break;

		func();
	}

	return 0;
}

Measured memory_bytes: 3200