#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <sstream>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <numeric>
#include <cctype>
#include <cassert>

// BEGIN CUT HERE
#ifdef _MSC_VER
#include <agents.h>
#endif
// END CUT HERE 

#define FOR(i, a, b) for(int i = (a); i < (int)(b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define REV(v) v.rbegin(), v.rend()
#define MEMSET(v, s) memset(v, s, sizeof(v))
#define MP make_pair
#define MT make_tuple
#define X first
#define Y second

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;



int main(){
	int n;
	while (cin >> n, n){
		map<string, map<int, vector<int>>> in, out;
		set<string> st;
		rep(i, n){
			string s;
			char c;
			int h, m, id;
			cin >> s >> h >> c >> m >> c >> id;
			if (c == 'I') in[s][id].push_back(h * 60 + m);
			if (c == 'O') out[s][id].push_back(h * 60 + m);
			st.insert(s);
		}
		map<int, int> m;
		for (auto date : st){
			auto mpin = in[date];
			auto mpout = out[date];
			if (!mpin.count(0)) continue;
			vector<int> &gin = mpin[0], &gout = mpout[0];
			rep(i, gin.size()){
				for (auto x : mpin){
					int sum = 0;
					if (x.first == 0) continue;
					vector<int> &vin = mpin[x.first], &vout = mpout[x.first];
					rep(j, vin.size()){
						int t = max(min(gout[i], vout[j]) - max(gin[i], vin[j]), 0);
						sum += t;
					}
					m[x.first] += sum;
				}
			}
		}
		int ans = 0;
		for (auto p : m) ans = max(ans, p.second);
		cout << ans << endl;
	}

	return 0;
}