### subroutines

def hm2min(hm)
  hh, mm = hm.split(':').map(&:to_i)
  hh * 60 + mm
end

### main

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

  users = []
  maxid = 0
  
  n.times do
    md, hm, io, id = gets.strip.split
    min = hm2min(hm)
    id = id.to_i
    maxid = id if maxid < id
    #p [md, hm, io, id]
    
    users[id] = {} if users[id].nil?
    users[id][md] = [] if users[id][md].nil?
    #p users[id][md]
    
    if io == 'I'
      users[id][md] << [min]
    else
      users[id][md].last << min
    end
  end
  #p users

  sums = (maxid + 1).times.map{0}
  for md in users[0].keys
    users[0][md].each do |gm0, gm1|
      for id in (1..maxid)
        next if users[id][md].nil?
        users[id][md].each do |im0, im1|
          if gm1 >= im0 && im1 >= gm0
            sums[id] += [gm1, im1].min - [gm0, im0].max
          end
        end
      end
    end
  end
  #p sums

  puts sums.max
end