### constant

INF = 1 << 30

### main

loop do
  n = gets.to_i
  break if n == 0

  cmds = {}
  dlrs = {}
  ordrs = []

  n.times do
    dlr, type, cmd, pr = gets.strip.split
    pr = pr.to_i
    #p ["new order", dlr, type, cmd, pr]
    
    dlrs[dlr] = [0, 0] if dlrs[dlr].nil?
    
    case type
    when 'SELL'
      max_pr = 0
      max_i = nil

      for i in (0...ordrs.length)
        dlr0, type0, cmd0, pr0 = ordrs[i]
        if dlr0 != dlr && type0 != type && cmd0 == cmd && pr0 >= pr &&
           max_pr < pr0
          max_pr = pr0
          max_i = i
        end        
      end
      
      if ! max_i.nil?
        mpr = ((pr + max_pr) * 0.5).floor
        #p [max_i] + ordrs[max_i] + [mpr]
        cmds[cmd] = [0, INF, 0, 0] if cmds[cmd].nil?
        cmds[cmd][0] += 1
        cmds[cmd][1] = mpr if cmds[cmd][1] > mpr
        cmds[cmd][2] += mpr
        cmds[cmd][3] = mpr if cmds[cmd][3] < mpr

        dlrs[dlr][1] += mpr
        dlrs[ordrs[max_i][0]][0] += mpr

        ordrs.delete_at(max_i)
      else
        ordrs << [dlr, type, cmd, pr]
      end

    when 'BUY'
      min_pr = INF
      min_i = nil

      for i in (0...ordrs.length)
        dlr0, type0, cmd0, pr0 = ordrs[i]
        if dlr0 != dlr && type0 != type && cmd0 == cmd && pr0 <= pr &&
           min_pr > pr0
          min_pr = pr0
          min_i = i
        end        
      end
      
      if ! min_i.nil?
        mpr = ((pr + min_pr) * 0.5).floor
        #p [min_i] + ordrs[min_i] + [mpr]
        cmds[cmd] = [0, INF, 0, 0] if cmds[cmd].nil?
        cmds[cmd][0] += 1
        cmds[cmd][1] = mpr if cmds[cmd][1] > mpr
        cmds[cmd][2] += mpr
        cmds[cmd][3] = mpr if cmds[cmd][3] < mpr

        dlrs[dlr][0] += mpr
        dlrs[ordrs[min_i][0]][1] += mpr

        ordrs.delete_at(min_i)
      else
        ordrs << [dlr, type, cmd, pr]
      end
    end
  end
  #p cmds
  #p dlrs

  for cmd in cmds.keys.sort
    num, min, sum, max = cmds[cmd]
    ave = (sum.to_f / num).to_i
    puts [cmd, min, ave, max].join(' ')
  end
  puts '-' * 2

  for dlr in dlrs.keys.sort
    puts ([dlr] + dlrs[dlr]).join(' ')
  end
  puts '-' * 10
end