#include <iostream>
#include <map>
#include <algorithm>
#include <vector>
#include <memory.h>
using namespace std;

#define Mon 35
#define DAY 1440
#define rep(i, n) for(int i = 0; i < n; i++)

map<string, int> id;
int cnt[1000];
vector<int> log[1000];
bool present[12*Mon*DAY];

int get_m(string day, string t){
  int d = (day[0]-'0')*10+(day[1]-'0')*Mon+(day[3]-'0')*10+(day[4]-'0');
  int m = ((t[0]-'0')*10+(t[1]-'0'))*60+(t[3]-'0')*10+(t[4]-'0');
  return d * DAY + m;
}

int main(){
  string day, tim, in, ID;
  int n, num;
  while(cin >> n && n){
    num = 1;
    int res = 0;
    
    id.clear();
    memset(cnt, 0, sizeof(cnt));
    memset(present, false, sizeof(present));
    rep(i, 1000) log[i].clear();

    rep(i, n){
      cin >> day >> tim >> in >> ID;
      if(id[ID] == 0) id[ID] = num++;
      log[id[ID]].push_back(get_m(day, tim));
    }
    int gd = id["000"];
    int sz = log[gd].size()/2;
    rep(i, sz){
      int s = log[gd][2*i];
      int t = log[gd][2*i+1];
      while(s<t){
	present[s] = true;
	s++;
      }
    }
    for(int i = 1; i < num; i++){
      if(i == gd) continue;
      int sz = log[i].size()/2;
      int c = 0;
      rep(j, sz){
	int s = log[i][j*2];
	int t = log[i][j*2+1];
	while(s < t) {
	  if(present[s++]) c++;
	}
      }
      res = max(res, c);
    }
    cout << res << endl;
  }
  return 0;
}