import std.stdio;
import std.ascii;
import std.range;
import std.array;
import std.functional;
import std.algorithm;
import std.conv;
import std.container;
import std.math;
import std.numeric;
import std.string;
import std.c.string;
import std.random;
import std.regex;
import std.typecons;

struct Event {
    string date;
    int time;
    string type;
    string id;
}

void main() {
    int N;
    Event[] events;
    bool input() {
        scanf("%d\n", &N);
        if (N == 0) return false;
        events.destroy;
        foreach (i; 0 .. N) {
            int h, m;
            string date;
            string e, id;
            auto x = readln.chomp.split;
            date = x[0];
            sscanf(x[1].ptr, "%d:%d".ptr, &h, &m);
            e = x[2];
            id = x[3];
            int time = h * 60 + m;
            events ~= Event(date, time, e, id);
        }
        return true;
    }
    void solve() {
        struct S {
            int time;
            string id;
        }
        S[] Q1, Q2;
        bool G;
        string prev;
        int[string] T;
        foreach (e; events) {
            static if (false) {
                writeln(e);
                writeln("\t", Q1);
                writeln("\t", Q2);
            }
            if (e.date != prev) {
                if (G) {
                    foreach (q; Q1) {
                        T[q.id] += e.time - q.time;
                    }
                }
                G = false;
                Q1.destroy;
                Q2.destroy;
                prev = e.date;
            }
            if (e.id == "000") {
                if (e.type == "I") {
                    foreach (q; Q2) {
                        Q1 ~= S(e.time, q.id);
                    }
                    Q2.destroy;
                    G = true;
                } else {
                    assert(e.type == "O");
                    foreach (q; Q1) {
                        T[q.id] += e.time - q.time;
                        Q2 ~= S(e.time, q.id);
                    }
                    Q1.destroy;
                    G = false;
                }
            } else {
                if (e.type == "I") {
                    (G ? Q1 : Q2) ~= S(e.time, e.id);
                } else {
                    S[] nQ;
                    foreach (q; (G ? Q1 : Q2)) {
                        if (q.id == e.id) {
                            //writeln(e.id, " out");
                            if (G) {
                                T[q.id] += e.time - q.time;
                            }
                        } else {
                            nQ ~= q;
                        }
                    }
                    (G ? Q1 : Q2) = nQ.dup;
                }
            }
        }
        writeln(T.reduce!max);
    }
    while (input) solve;
}