#include<cstdio>
#include<iostream>
#include<sstream>
#include<iomanip>
#include<cstring>
#include<string>
#include<cmath>
#include<cstdlib>
#include<algorithm>
#include<functional>
#include<cctype>
#include<ctime>
#include<stack>
#include<queue>
#include<deque>
#include<vector>
#include<set>
#include<map>
#include<limits>
using namespace std;
#define INT (0x3f3f3f3f)*2
#define LL (0x3f3f3f3f3f3f3f3f)*2
#define clr(a) memset(a,0,sizeof(a))
#define clr_minus1(a) memset(a,-1,sizeof(a))
#define clr_NULL(a) memset(a,NULL,sizeof(a))
#define clr_1(a,n) for(int i=0;i<=n;i++) a[i]=1
#define clr_INT(a) memset(a,INT,sizeof(a))
#define clr_true(a) memset(a,true,sizeof(a))
#define clr_false(a) memset(a,false,sizeof(a))
#define clr_queue(q) while(!q.empty()) q.pop()
#define clr_stack(s) while(!s.empty()) s.pop()
#define clr_vector(v,n) for(int i=0;i<=n;i++) v[i].clear()
#define rep(i, a, b) for (int i = a; i < b; i++)
#define dep(i, a, b) for (int i = a; i > b; i--)
#define repin(i, a, b) for (int i = a; i <= b; i++)
#define depin(i, a, b) for (int i = a; i >= b; i--)
#define Max(a,b) ((a)>(b) ? (a):(b))
#define Min(a,b) ((a)<(b) ? (a):(b))
int month[]= {0,31,28,31,30,31,30,31,31,30,31,30,31};
int month_sum[12];
struct Per
{
    int month;
    int day;
    int h;
    int m;
    char flag;
    int num;
    int time;
    int days;
    int times;
};
Per per[1010];
struct Tem
{
    int days;
    int times;
    int num;
};
Tem temp[1010];
Tem fina[1010];
int fina_sum[1010];
void check(int mx,int pos)
{
    for(int i=1; i<=mx; i++)
    {
        if(temp[i].days!=-1)
        {
            if(temp[i].days*3600+temp[i].times<=temp[0].days*3600+temp[0].times)
            {
                fina_sum[i]+=(per[pos].days-temp[0].days)*3600-(per[pos].days-temp[0].days)*2+per[pos].times-temp[0].times;

            }
            else
            {
                fina_sum[i]+=(per[pos].days-temp[i].days)*3600-(per[pos].days-temp[i].days)*2+per[pos].times-temp[i].times;
            }
        }
    }
}
int main()
{
    int n;
    while(scanf("%d",&n)==1&&n)
    {
        char a,b,c,d,e;
        int num_maxs=-1;
        for(int i=0; i<n; i++)
        {
            scanf("%d%c%d%c%d%c%d%c%c%c%d",&per[i].month,&a,&per[i].day,&b,&per[i].h,&c,&per[i].m,&d,&per[i].flag,&e,&per[i].num);
            if(num_maxs<per[i].num) num_maxs=per[i].num;
        }
        int sum=0;
        for(int i=1; i<=12; i++)
        {
            sum+=month[i-1];
            month_sum[i]=sum;
        }
//    for(int i=1;i<=12;i++) printf("%d ",month_sum[i]);
//    printf("\n");
        for(int i=0; i<n; i++)
        {
            per[i].days=month_sum[per[i].month]+per[i].day;
            per[i].times=per[i].h*60+per[i].m;
            //printf("%d %d %d %d %c %d\n",per[i].month,per[i].day,per[i].h,per[i].m,per[i].flag,per[i].num);
        }
        for(int i=0; i<=num_maxs; i++)
        {
            temp[i].days=-1;
            temp[i].times=-1;
        }
        memset(fina,0,sizeof(fina));
        int tot=0;
        memset(fina_sum,0,sizeof(fina_sum));
        for(int i=0; i<n; i++)
        {
            if(per[i].num==0)
            {
                if(per[i].flag=='I')
                {
                    temp[0].days=per[i].days;
                    temp[0].times=per[i].times;
                }
                else
                {
                    check(num_maxs,i);
                    temp[0].days=-1;
                    temp[0].times=-1;
                }
            }
            else
            {
                if(per[i].flag=='I')
                {
                    temp[per[i].num].days=per[i].days;
                    temp[per[i].num].times=per[i].times;
                }
                else
                {
                    if(temp[0].days==-1) ;
                    else
                    {
                        if(temp[0].days*3600+temp[0].times<=temp[per[i].num].days*3600+temp[per[i].num].times)
                        {
                            fina_sum[per[i].num]+=(per[i].days-temp[per[i].num].days)*3600+per[i].times-temp[per[i].num].times;

                        }
                        else
                        {
                            fina_sum[per[i].num]+=(per[i].days-temp[0].days)*3600+per[i].times-temp[0].times;
                        }
                    }
                     temp[per[i].num].days=-1;
                    temp[per[i].num].times=-1;
                }
            }
        }
        int maxs=-1;
        for(int i=1; i<=num_maxs; i++)
        {
            //printf("%d ",fina_sum[i]);
            if(maxs<fina_sum[i]) maxs=fina_sum[i];
        }
        //printf("\n");
        printf("%d\n",maxs);
    }
    return 0;
}

Measured memory_bytes: 1256