var n;
var t = [];
var x = [];
var s = [];

function time(s){
	s = s.split(':');
	return (+s[0]) * 60 + (+s[1]);
}

function same(a, b){
	return a[0] === b[0] && a[1] === b[1];
}

function main(){
	while(n = scan()){
		rep(1000, function(i){
			x[i] = [];
		});

		rep(n, function(){
			var v = [scan_string(), time(scan_string())];
			if(t.length === 0 || !same(t[t.length - 1], v)){
				t.push(v);
			}
			scan_string();
			x[scan()].push(t.length - 1);
		});

		rep(t.length, function(i){
			s[i] = 0;
		});
		rep(x[0].length, function(i){
			if(i % 2){
				rep(x[0][i - 1], x[0][i], function(j){
					s[j + 1] = t[j + 1][1] - t[j][1];
				});
			}
		});
		rep(t.length - 1, function(i){
			s[i + 1] += s[i];
		});

		var ans = 0;
		rep(1, 1000, function(i){
			var a = 0;
			rep(x[i].length, function(j){
				if(j % 2){
					a += s[x[i][j]] - s[x[i][j - 1]];
				}
			});
			ans = Math.max(a, ans);
		});
		print(ans);

		t = [];
	}
}

function rep(a, b, c, u){
	if(c === u){
		c = b;
		b = a;
		a = 0;
	}
	for(var i = a; i < b; ++i){
		if(c(i) === false){
			break;
		}
	}
}

var input = '';

function scan(){
	return +input.pop();
}
function scan_string(){
	return input.pop();
} 
function print(val){
	console.log(val);
}
 
process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.on('data', function(chunk){
	input += chunk;
});
process.stdin.on('end', function(){
	input = input.trim().split(/\s+/).reverse();
	main();
});