#include<stdio.h>
#include<string.h>
main(){
    char a[10];
    int n,i,out=0,base=0,score=0;
    scanf("%d",&n);
    while(n!=0){
        scanf("%s",a);
        if(!strcmp(a,"HIT")){
            base++;
            if(base>3){
                base--;
                score++;
            }
        }
        if(!strcmp(a,"OUT")){
        out++;
        }
        if(!strcmp(a,"HOMERUN")){
            score+=base+1;
            base=0;
        }
        if(out==3){
            n--;
            out=0;
            printf("%d\n",score);
            score=0;
            base=0;
        }
    }
}