#include <iostream>
#include <string>
#include <sstream>
#include <cstring>
using namespace std;

int N;
bool endow[1000];
int tm[1000], tt[1000];

pair<int, int> separete(string s)
{
    stringstream ss(s);
    int a,b;
    char c;

    ss >> a >> c >> b;

    return make_pair(a,b);
}

int transMin(string s)
{
    pair<int, int> ms = separete(s);
    int m = ms.first;
    int d = ms.second;

    return m*60+d;
}

int solve()
{
    memset(endow, 0, sizeof(endow));
    memset(tt, 0, sizeof(tt));
    
    while(N--){
	string a,b,c;
	int mn, id;

	cin >> a >> b >> c >> id;
	mn = transMin(b);

	if(c == "I") {
	    endow[id] = true;
	    tm[id] = mn;
	}

	if(c == "O") {
	    endow[id] = false;
	    if(id != 0) {
		if(endow[0]) tt[id] += mn - max(tm[id], tm[0]);
	    }
	    else {
		for(int i=1; i<1000; i++)
		    if(endow[i]) tt[i] += mn - max(tm[i], tm[0]);
	    }
	}
    }

    int res = 0;
    for(int i=1; i<1000; i++)
	res = max(res, tt[i]);

    return res;
}

    
    

int main()
{
    while(cin >> N, N)
	cout << solve() << endl;
    
}