#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>

using namespace std;

#define FOR(i,k,n) for(int i=(k); i<(int)n; ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

template<class T> void debug(T begin, T end){ for(T i = begin; i != end; ++i) cout<<*i<<" "; cout<<endl; }

typedef long long ll;
const int INF = 100000000;
const double EPS = 1e-8;
const int MOD = 1000000007;
struct order{
  string dealer, type, commodity;
  int price;
  order(string d, string t, string c, int p) :
    dealer(d), type(t), commodity(c), price(p) {}
};

order parse(){
  string d, t, c;
  int p;
  cin>>d>>t>>c>>p;
  return order(d, t, c, p);
}

int main(){
  int N;
  while(cin>>N && N){
    vector<order> orders;
    map<string, int> d_buy;
    map<string, int> d_sell;
    map<string, vector<int> > c_trade;
    REP(i, N){
      order od = parse();
      vector<order>::iterator tr_i = orders.end();
      d_buy[od.dealer] += 0;
      d_sell[od.dealer] += 0;
      if(od.type == "BUY"){
        FORIT(it, orders){
          if((it->type == "SELL" && it->commodity == od.commodity && it->price <= od.price && it->dealer != od.dealer)
              && (tr_i == orders.end() || tr_i->price > it->price)){
            tr_i = it;
          }
        }
        if(tr_i != orders.end()){
          int price = (od.price + tr_i->price) / 2;
          //printf("%s buy %s from %s by %d yen\n", od.dealer.c_str(), od.commodity.c_str(), tr_i->dealer.c_str(), price);
          d_buy[od.dealer] += price;
          d_sell[tr_i->dealer] += price;
          c_trade[od.commodity].push_back(price);
          orders.erase(tr_i);
        }else{
          orders.push_back(od);
        }
      }else{
        FORIT(it, orders){
          if((it->type == "BUY" && it->commodity == od.commodity && it->price >= od.price && it->dealer != od.dealer)
              && (tr_i == orders.end() || tr_i->price < it->price)){
            tr_i = it;
          }
        }
        if(tr_i != orders.end()){
          int price = (od.price + tr_i->price) / 2;
          //printf("%s sell %s to %s by %d yen\n", od.dealer.c_str(), od.commodity.c_str(), tr_i->dealer.c_str(), price);
          d_sell[od.dealer] += price;
          d_buy[tr_i->dealer] += price;
          c_trade[od.commodity].push_back(price);
          orders.erase(tr_i);
        }else{
          orders.push_back(od);
        }
      }
    }
    //cout<<"-"<<endl;
    FORIT(it, c_trade){
      string name = it->first;
      vector<int> v = it->second;
      sort(v.begin(), v.end());
      int a = v.front();
      int c = v.back();
      int b = 0;
      REP(i, v.size()) b += v[i];
      b /= v.size();
      printf("%s %d %d %d\n", name.c_str(), a, b, c);
    }
    cout<<"--"<<endl;
    FORIT(it, d_sell){
      string name = it->first;
      printf("%s %d %d\n", name.c_str(), d_buy[it->first], it->second);
    }
    cout<<"----------"<<endl;
  }
  return 0;
}