#define _USE_MATH_DEFINES
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<ll, int> ll_i;
typedef pair<double, int> d_i;
typedef pair<ll, ll> ll_ll;
typedef pair<double, double> d_d;
struct edge { int u, v; double w; };

ll MOD = 10000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

int calc(int a, int b, int c, int d) {
	return max(0, min(b, d) - max(a, c));
}

int main() {
	for (;;) {
		int n; cin >> n;
		if (n == 0) break;
		vector< vector<int> > ti(1000), to(1000);
		while (n--) {
			int M, D, h, m, p; char e;
			scanf("%d/%d %d:%d %c %d", &M, &D, &h, &m, &e, &p);
			int t = ((M * 31 + D) * 24 + h) * 60 + m;
			if (e == 'I') ti[p].push_back(t);
			else if (e == 'O') to[p].push_back(t);
		}
		vector<int> sum(1000);
		for (int p = 1; p < 1000; p++)
			for (int i = 0; i < ti[p].size(); i++)
				for (int j = 0; j < ti[0].size(); j++)
					sum[p] += calc(ti[p][i], to[p][i], ti[0][j], to[0][j]);
		int ans = 0;
		for (int p = 1; p < 1000; p++)
			ans = max(ans, sum[p]);
		cout << ans << endl;
	}
}