//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <climits>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <queue>
#include <random>
#include <cctype>
#include <complex>
#include <regex>

using namespace std;

#define C_MAX(a, b) ((a)>(b)?(a):(b))
#define SHOW_VECTOR(v) {std::cerr << #v << "\t:";for(const auto& xxx : v){std::cerr << xxx << " ";}std::cerr << "\n";}
#define SHOW_MAP(v){std::cerr << #v << endl; for(const auto& xxx: v){std::cerr << xxx.first << " " << xxx.second << "\n";}}

struct Data {
    int time;
    string which;
    string id;
};

struct Per {
    int start;
    int end;
    string id;
};

int getTime(string s) {
    int hour = stoi(s.substr(0, 2));
    int minute = stoi(s.substr(3, 2));
    int time = hour * 60 + minute;
    return time;
}

int main() {

    while (true) {

        int N;
        cin >> N;

        if (N == 0) break;

        string pre = "";
        vector<vector<Data>> datas;
        for (int i = 0; i < N; i++) {
            string date, ti, which, id;
            cin >> date >> ti >> which >> id;
            int time = getTime(ti);
            if (i == 0) {
                datas.push_back(vector<Data>());
                datas.back().push_back((Data) {time, which, id});
                pre = date;
                continue;
            }
            if (pre == date) datas.back().push_back((Data) {time, which, id});
            else {
                datas.push_back(vector<Data>());
                datas.back().push_back((Data) {time, which, id});
                pre = date;
            }
        }

        map<string, int> M;
        for (int i = 0; i < datas.size(); i++) {
            vector<Per> god;
            vector<Per> other;
            int have = -1;
            for (int j = 0; j < datas[i].size(); j++) {
                auto data = datas[i][j];
                if (data.id == "000") {
                    if (have == -1) have = data.time;
                    else {
                        god.push_back((Per) {have, data.time, "000"});
                        have = -1;
                    }
                }
            }
            map<string, int> has;
            for (int j = 0; j < datas[i].size(); j++) has[datas[i][j].id] = -1;
            for (int j = 0; j < datas[i].size(); j++) {
                auto data = datas[i][j];
                if (data.id != "000") {
                    if (has[data.id] == -1) has[data.id] = data.time;
                    else {
                        other.push_back((Per) {has[data.id], data.time, data.id});
                        has[data.id] = -1;
                    }
                }
            }
            for (auto go: god) {
                for (auto ot: other) {
                    int minV = max(go.start, ot.start);
                    int maxV = min(go.end, ot.end);
                    int d = maxV - minV;
                    M[ot.id] += max(0, d);
                }
            }
        }

        int ansV = 0;
        for (auto x: M) ansV = max(ansV, x.second);

        cout << ansV << endl;

    }

}














































Measured memory_bytes: 3344