#include <bits/stdc++.h>
using namespace std;
int main(){
  while (1){
    int n;
    cin >> n;
    if (n == 0){
      break;
    }
    vector<int> M(n), D(n), h(n), m(n);
    vector<char> e(n);
    vector<int> p(n);
    for (int i = 0; i < n; i++){
      char c1, c2;
      cin >> M[i] >> c1 >> D[i] >> h[i] >> c2 >> m[i] >> e[i] >> p[i];
    }
    vector<int> time(n);
    for (int i = 0; i < n; i++){
      time[i] = ((M[i] * 40 + D[i]) * 24 + h[i]) * 60 + m[i];
    }
    vector<int> t(1000, 0);
    vector<bool> c(1000, false);
    for (int i = 0; i < n; i++){
      if (e[i] == 'I'){
        c[p[i]] = true;
      }
      if (e[i] == 'O'){
        c[p[i]] = false;
      }
      if (i < n - 1 && c[0]){
        int dt = time[i + 1] - time[i];
        for (int j = 1; j < 1000; j++){
          if (c[j]){
            t[j] += dt;
          }
        }
      }
    }
    int ans = 0;
    for (int j = 1; j < 1000; j++){
      ans = max(ans, t[j]);
    }
    cout << ans << endl;
  }
}
