//Hello. I'm Peter.
#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 input freopen("data.txt","r",stdin)
#define output freopen("output.txt","w",stdout)
#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_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 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 ll long long
#define eps
#define MOD
#define MAXN
#define N 1010
#define M 100
char row[M];
struct Personality
{
    ll month;
    ll day;
    ll hour;
    ll minute;
    bool open;
    ll ans;
}god,nor[N],now;
int n;
ll month,day,hour,minute;
char open,c;
ll sixty=60;
ll twentyfour=24;
ll monthlimit[15];
ll tellmethetime(int w,int id1)
{
    ll res=0,t;
    if(!w)//隶。邂怜ス灘燕?紅od in 逧?慮髣エ蟾ョ
    {
        if(month==god.month && day==god.day)
        {
            if(hour==god.hour) res+=minute-god.minute;
            else
            {
                res+=sixty-god.minute;
                res+=minute;
                t=hour-god.hour-1;
                res+=t*sixty;
            }
        }
        else
        {
            //蜈育ョ嶺ケ句燕驍」螟ゥ蛻ー荳倶ク?ク?、ゥ闃ア莠?、壼ー大?髓?            res+=sixty-god.minute;
            t=twentyfour-god.hour-1;
            res+=t*sixty;
            //蜀咲ョ怜ス灘、ゥ蛻ー蠖灘、ゥ蠑?ァ玖干莠?、壼ー第慮髣エ
            res+=hour*sixty;
            res+=minute;
            //蜀咲ョ怜ス灘、ゥ蛻ー荵句燕驍」荳?、ゥ闃ア莠?、壼ー大、ゥ?御ク崎ソ?ヲ∝?1蝟?.0
            if(month==god.month)
            {
                t=0;
                t+=day-god.day;
            }
            else
            {
                t=0;
                //蜈育ョ怜ス捺怦闃ア莠?、壼ー大、ゥ
                t+=day;
                //蜀咲ョ鈴ぅ譛郁干莠?、壼ー大、ゥ
                t+=monthlimit[god.month]-god.day;
                //蜀咲ョ鈴ぅ譛亥芦蠖捺怦闃ア莠?、壼ー大、ゥ
                for(ll i=god.month+1;i<month;i++)
                {
                    t+=monthlimit[i];
                }
            }
            t-=1;
            //蟆?、ゥ蜿俶?蛻?帖
            res+=t*twentyfour*sixty;
        }
    }
    else//隶。邂怜ス灘燕-person in 逧?慮髣エ蟾ョ
    {
        res=0;
        now=nor[id1];
        if(now.month==month && now.day==day)
        {
            if(hour==now.hour) res+=minute-now.minute;
            else
            {
                res+=sixty-now.minute;
                res+=minute;
                t=hour-now.hour-1;
                res+=t*sixty;
            }
        }
        else
        {
            //蜈育ョ嶺ケ句燕驍」螟ゥ蛻ー荳倶ク?ク?、ゥ闃ア莠?、壼ー大?髓?            res+=sixty-now.minute;
            t=twentyfour-now.hour-1;
            res+=t*sixty;
            //蜀咲ョ怜ス灘、ゥ蛻ー蠖灘、ゥ蠑?ァ玖干莠?、壼ー第慮髣エ
            res+=minute;
            res+=hour*sixty;
            //蜀咲ョ怜ス灘、ゥ蛻ー荵句燕驍」荳?、ゥ闃ア莠?、壼ー大、ゥ?御ク崎ソ?ヲ∝?1蝟?.0
            if(now.month==month)
            {
                t=day-now.day;
            }
            else
            {
                t=0;
                t+=monthlimit[now.month]-now.day;
                t+=day;
                for(ll i=now.month+1;i<month;i++)
                {
                    t+=monthlimit[i];
                }
            }
            t-=1;
            res+=t*twentyfour*sixty;
        }
    }
    return res;
}
int main()
{
//    input;
    monthlimit[1]=31;
    monthlimit[2]=28;
    monthlimit[3]=31;
    monthlimit[4]=30;
    monthlimit[5]=31;
    monthlimit[6]=30;
    monthlimit[7]=31;
    monthlimit[8]=31;
    monthlimit[9]=30;
    monthlimit[10]=31;
    monthlimit[11]=30;
    monthlimit[12]=31;
    ll t1,t2,ans;
    int id;
    while(~scanf("%d",&n) && n)
    {
        clr(nor);
        repin(i,1,n)
        {
            scanf(" %lld %c %lld %lld %c %lld %c %d",&month,&c,&day,&hour,&c,&minute,&open,&id);
            if(!id)//godness
            {
                if(open=='O')
                {
                    god.open=false;
                    repin(i,1,999)
                    {
                        if(!nor[i].open) continue;
                        t1=tellmethetime(0,i);//蠖灘燕螟ゥ-god in
                        t2=tellmethetime(1,i);//蠖灘燕螟ゥ-person in
                        nor[i].ans+=min(t1,t2);
                    }
                }
                else if(open=='I')
                {
                    god.open=true;
                    god.month=month;
                    god.day=day;
                    god.hour=hour;
                    god.minute=minute;
                }
                continue;
            }
            if(open=='I' && id!=0)
            {
                nor[id].month=month;
                nor[id].day=day;
                nor[id].hour=hour;
                nor[id].minute=minute;
                nor[id].open=true;
                continue;
            }
            else if(open=='O' && id!=0)
            {
                nor[id].open=false;
                if(!god.open) continue;
                t1=tellmethetime(0,id);//蠖灘燕螟ゥ-god in
                t2=tellmethetime(1,id);//蠖灘燕螟ゥ-person in
                nor[id].ans+=min(t1,t2);
            }
        }
        ans=0;
        repin(i,1,999)
        {
            ans=max(ans,nor[i].ans);
//            printf("nor[%d].ans=%lld\n",i,nor[i].ans);
        }
        cout<<ans<<endl;
    }
}

Measured memory_bytes: 1268