import std.stdio;
import std.container;
import std.algorithm;

void main(){
	while(true){
		int n;
		readf("%d\n", &n);
		if(n == 0) break;
		int[1000] itime = 0;
		auto islogin = redBlackTree!(false,int)();
		int month=-1, date=-1;
		bool logined = false;
		while(n--){
			int m, d, hour, minute, p;
			int time;
			char e;
			readf("%d/%d %d:%d %s %d\n", &m, &d, &hour, &minute, &e, &p);
			time = 60*hour+minute;
			if(d != date || m != month){
				if(logined)
					foreach(i; islogin)
						itime[i] += 24*60;
				logined = false;
				date = d; month = m;
				islogin.clear();
			}
			if(e == 'I'){
				if(p == 0){
					logined = true;
					foreach(i; islogin)
						itime[i] -= time;
				}else{
					islogin.insert(p-1);
					if(logined)	itime[p-1] -= time;
				}
			}else{
				if(p == 0){
					logined = false;
					foreach(i; islogin)
						itime[i] += time;
				}else{
					islogin.removeKey(p-1);
					if(logined)	itime[p-1] += time;
				}
			}
		}
		writeln(reduce!max(0, itime));
	}
}