#include<bits/stdc++.h>
using namespace std;

int N;
int bless[1000];
int state[1000];

int tominute(string& time){
	return stoi(time.substr(0, 2)) * 60 + stoi(time.substr(3, 2));
}

int main(){
	while(cin >> N, N){
		for(int i = 0; i < 1000; i++){
			bless[i] = 0;
			state[i] = 0;
		}
		string prev = "";
		int prevm = 0;
		for(int i = 0; i < N; i++){
			string day, time;
			char c;
			int id;
			cin >> day >> time >> c >> id;
			int m = tominute(time);
			int dm;
			if(day == prev){
				dm = m - prevm;	
			}else{
				dm = m;
			}
			if(state[0]){
				for(int i = 1; i < 1000; i++){
					if(state[i]){
						bless[i] += dm;
					}
				}
			}
			if(c == 'I'){
				state[id] = 1;
			}else{
				state[id] = 0;
			}
			
			prev = day;
			prevm = m;
		}
		int mv = 0;
		for(int i = 1; i < 1000; i++){
			mv = max(mv, bless[i]);
		}
		cout << mv << endl;
	}
}