#include<iostream>
#include<map>
#include<algorithm>
#include<vector>
using namespace std;
#define REP(i,b,n) for(int i=b;i<n;i++)
#define rep(i,n)   REP(i,0,n)
#define ALL(C)     (C).begin(),(C).end()


class Com{
  public:
  string name;
  int low,ave,high,num;
  bool operator<(const Com & a)const{
    return name < a.name;
  }
};

class Dea{
public:
  string name;
  int rec,pay;
  bool operator<(const Dea & a)const{
    return name < a.name;
  }
};

typedef struct{
  int cid,did;
  string cname,dname;
  bool used;
  bool isbuy;
  int price;
}info;

void solve(vector<info> & in,vector<Com> C,vector<Dea> D);

template<class T>
int getname(string a,map<string,int> & M,vector<T> &b,T in){
  int index = M.size();
  if (M.find(a) == M.end())b.push_back(in),M[a]=index;
  return M[a];
}

int main(){
  int n;
  while(cin>>n && n){
    vector<info> in;
    vector<Com> C;
    vector<Dea> D;
    map<string,int> Dname,Cname;
    rep(i,n){
      info tmp;
      Com a=(Com){"",(1<<21),0,0,0};
      Dea b=(Dea){"",0,0};
      string order;
      cin>>tmp.dname>>order>>tmp.cname>>tmp.price;
      if (order == "SELL")tmp.isbuy=false;
      else tmp.isbuy=true;
      tmp.used=false;
      
      a.name=tmp.cname;
      b.name=tmp.dname;
      tmp.cid=getname(tmp.cname,Cname,C,a);
      tmp.did=getname(tmp.dname,Dname,D,b);
      
      in.push_back(tmp);
    }
    
    solve(in,C,D);
  }
}

void solve(vector<info> & in,vector<Com> C,vector<Dea> D){
  rep(i,in.size()){
    int price,index=-1;
    if (in[i].isbuy)price=(1<<21);
    else price = 0;

    if (in[i].used)continue;
    rep(j,i){
      if (in[j].used||in[i].did == in[j].did ||
	  in[i].cid != in[j].cid || in[i].isbuy==in[j].isbuy)continue;
      if (in[i].isbuy){//buy
	if (!(in[j].price<=in[i].price))continue;
	if (in[j].price  < price)price=in[j].price,index=j;
      }else {//sell
	if (!(in[i].price<=in[j].price))continue;
	if (price < in[j].price)price=in[j].price,index=j;
      }
    }

    if (index == -1)continue;

    in[i].used=in[index].used=true;

    info sell = in[i],buy=in[index];
    if (!buy.isbuy)swap(sell,buy);
    int ave = (sell.price+buy.price)/2;
    C[sell.cid].low=min(C[sell.cid].low,ave);
    //C[sell.cid].ave+=sell.price+buy.price;//critical
    C[sell.cid].ave+=ave;//
    C[sell.cid].high=max(C[sell.cid].high,ave);
    C[sell.cid].num++;
    
    D[sell.did].rec+=ave;
    D[buy.did].pay+=ave;
  }


  sort(ALL(C));
  sort(ALL(D));
  rep(i,C.size()){
    if (C[i].ave == 0)continue;
    printf("%s %d %d %d\n",C[i].name.c_str(),C[i].low,
	   C[i].ave/C[i].num,C[i].high);
  }
  puts("--");
  rep(i,D.size()){
    //if (D[i].rec == 0 && D[i].pay == 0)continue;
    printf("%s %d %d\n",D[i].name.c_str(),D[i].pay,D[i].rec);
  }
  puts("----------");
}