while 1:

    n = int(input())

    if n == 0: break

    exist = set([])

    time = [0]*1000

    bless = [0]*1000

    for loop in range(n):

        md,hm,io,p = input().split()

        h,m = list(map(int,hm.split(":")))

        t = 60*h+m

        p = int(p)

        if io == "I":

            time[p] = t

            exist.add(p)

        else:

            exist.remove(p)

            if p == 0:

                for i in exist: bless[i] += t-max(time[p],time[i])

            elif 0 in exist:

                bless[p] += t-max(time[0],time[p])

    print(max(bless))

    
while 1:

    n = int(input())

    if n == 0: break

    exist = set([])

    enter = [0]*1000

    bless = [0]*1000

    for loop in range(n):

        md,hm,io,p = input().split()

        h,m = list(map(int,hm.split(":")))

        t = 60*h+m

        p = int(p)

        if io == "I":

            enter[p] = t

            exist.add(p)

        else:

            exist.remove(p)

            if p == 0:

                for i in exist: bless[i] += t-max(enter[p],enter[i])

            elif 0 in exist:

                bless[p] += t-max(enter[0],enter[p])

    print(max(bless))

    
while 1:
    n = int(input())
    if n == 0:
        break
    exist = set([])
    time = [0] * 1000
    bless = [0] * 1000
    for loop in range(n):
        md, hm, io, p = input().split()
        h, m = list(map(int, hm.split(":")))
        t = 60 * h + m
        p = int(p)
        if io == "I":
            time[p] = t
            exist.add(p)
        else:
            exist.remove(p)
            if p == 0:
                for i in exist:
                    bless[i] += t - max(time[p], time[i])
            elif 0 in exist:
                bless[p] += t - max(time[0], time[p])
    print(max(bless))

while 1:
    n = int(input())
    if n == 0:
        break
    exist = set([])
    enter = [0] * 1000
    bless = [0] * 1000
    for loop in range(n):
        md, hm, io, p = input().split()
        h, m = list(map(int, hm.split(":")))
        t = 60 * h + m
        p = int(p)
        if io == "I":
            enter[p] = t
            exist.add(p)
        else:
            exist.remove(p)
            if p == 0:
                for i in exist:
                    bless[i] += t - max(enter[p], enter[i])
            elif 0 in exist:
                bless[p] += t - max(enter[0], enter[p])
    print(max(bless))

-    time = [0] * 1000 +    enter = [0] * 1000 -            time[p] = t +            enter[p] = t -                    bless[i] += t - max(time[p], time[i]) +                    bless[i] += t - max(enter[p], enter[i]) -                bless[p] += t - max(time[0], time[p]) +                bless[p] += t - max(enter[0], enter[p])