#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <utility>
#include <cstring>
const int MOD = 1e9 + 7;
const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, 1, -1};
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
struct human
{
    vector<int> inout;
    vector<int> date;
};
struct god
{
    int in, out, date;
};
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    while(cin >> N, N)
    {
        human info_h[N + 1];
        god info_g[N + 1];
        int last;
        string day, time, inout, num;
        int pos1 = 0, pos2 = 0;
        vector<int> programer(1000, 0);
        for(int i = 0; i < N; i++)
        {
            cin >> day >> time >> inout >> num;
            string tmp_s = day.substr(0, 2);
            tmp_s += day.substr(3);
            int tmp_time = stoi(time.substr(0, 2)) * 60 + stoi(time.substr(3));
            int tmp_num = stoi(num);
            int tmp_day = stoi(tmp_s);
            if(tmp_num == 0)
            {
                if(inout == "I")
                {
                    info_g[pos1].in = tmp_time;
                    info_g[pos1].date = tmp_day;
                }
                else
                {
                    info_g[pos1].out = tmp_time;
                    info_g[pos1].date = tmp_day;
                    pos1++;
                }
            }
            else
            {
                if(inout == "I")
                {
                    info_h[tmp_num].inout.push_back(tmp_time);
                    info_h[tmp_num].date.push_back(tmp_day);
                }
                else
                {
                    info_h[tmp_num].inout.push_back(tmp_time);
                    info_h[tmp_num].date.push_back(tmp_day);
                }
            }
        }
        for(int i = 0; i < pos1; i++)
        {
            for(int j = 0; j < N; j++)
            {
                for(int k = 0; k < info_h[j].inout.size(); k += 2)
                {
                    if(info_h[j].inout[k] > info_g[i].out || info_h[j].inout[k + 1] < info_g[i].in)
                        continue;
                    if(info_g[i].date != info_h[j].date[k])
                        continue;
                    programer[j] += min(info_h[j].inout[k + 1], info_g[i].out) - max(info_h[j].inout[k], info_g[i].in);
                }
            }
        }
        int ans = 0;
        for(int i = 0; i < N; i++)
        {
            if(programer[i] > ans)
                ans = programer[i];
        }
        cout << ans << endl;
    }
    return 0;
}
