#include <bits/stdc++.h>
using namespace std;
#define int long long   // <-----!!!!!!!!!!!!!!!!!!!

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
#define rrep2(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define all(a) (a).begin(),(a).end()

typedef long long ll;
typedef pair<int, int> Pii;
typedef tuple<int, int, int> TUPLE;
typedef vector<int> V;
typedef vector<V> VV;
typedef vector<VV> VVV;

struct Range {
    string d;
    int l, r;
    int id;
    void print() {
        cout << d << " " << l << " " << r << " " << id << endl;
    }
};

int strToInt(string s) {
    int ret = 0;
    int sign = 1;

    int i = 0;
    if (s[0] == '-') {
        i++;
        sign = -1;
    }

    while (i < s.size()) {
        ret *= 10;
        ret += s[i] - '0';
        i++;
    }

    return ret * sign;
}

int convTime(string s) {
    int ret = 0;
    stringstream ss(s);
    string t;
    while (getline(ss, t, ':')) {
        ret *= 60;
        // ret += stoi(t);
        ret += strToInt(t);
    }
    return ret;
}

int common(const Range &a, const Range &b) {
    if (a.d != b.d) return 0;
    if (b.id == 0) return 0;
    int l = max(a.l, b.l);
    int r = min(a.r, b.r);
    return max(0LL, r - l);
}

signed main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);

    int n;
    while (cin >> n, n) {
        vector<stack<int>> v(1000);
        vector<Range> u;
        rep(i, n) {
            string d, hhmm, e;
            int id;
            cin >> d >> hhmm >> e >> id;
            int m = convTime(hhmm);
            if (v[id].empty()) {
                assert(e == "I");
                v[id].push(m);
            } else {
                assert(e == "O");
                int s = v[id].top(); v[id].pop();
                u.emplace_back((Range){d, s, m, id});
            }
        }

        // for (auto r : u) {
        //     cout << r.d << " " << r.l << " " << r.r << " " << r.id << endl;
        // }

        V len(1000, 0);
        for (auto a : u) {
            if (a.id == 0) {
                for (auto b : u) {
                    len[b.id] += common(a, b);
                    // a.print();
                    // b.print();
                    // cout << common(a, b) << endl;
                }
            }
        }

        cout << *max_element(all(len)) << endl;

        // rep(i, 5) {
        //     cout << len[i] << " ";
        // }
        // cout << endl;
    }
}