loop do
    n = gets.to_i
    break if n == 0
    data = Hash.new(Array.new)
    n.times do
        s = gets.chomp.split
        time = s[1].split(/:/)
        data[s[0]] += [[time[0].to_i * 60 + time[1].to_i, s[2],s[3]]]
    end
    ret = Hash.new(0)
    data.each do |k,v|
        gd_presence = Array.new
        v.select{|vs| vs[2] == "000"}.each_slice(2) do |gd|
            gd_presence.push([gd[0][0],gd[1][0]])
        end
        io = Hash.new(Array.new)
        v.select{|vs| vs[2] != "000"}.each do |pg|
            io[pg[2]] += [pg[0]]
        end
        io.each do |pg|
            total = 0
            pg[1].each_slice(2) do |time|
                gd_presence.each do |gdp|
                    ret[pg[0]] += [0,[time[1],gdp[1]].min-[time[0],gdp[0]].max].max
                end
            end
        end
    end
    output = ret.map{|a| a[1]}.max
    p output ? output : 0
end