#include<iostream>
#include<cstdio>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;
typedef long long int ll;

int main()
{
    string ss;
	int out=0,point=0;
	bool base[3];
	int xx=0;
	int n;
	cin >> n;
	base[0]=base[1]=base[2]=false;
	while(xx<n){
		cin >> ss;
		if(ss=="HIT"){
			if(base[2]){
				point++;
			}
			if(base[1]){
				base[2]=true;
			}
			if(base[0]){
				base[1]=true;
			}
			base[0]=true;
		}
		else if(ss=="OUT"){
			out++;
			if(out==3){
				printf("%d\n",point);
				xx++;
				point=out=0;
				for(int i=0;i<3;i++)base[i]=false;
			}
		}
		else{
			point++;
			if(base[2]){
				point++;
				base[2]=false;
			}
			if(base[1]){
				point++;
				base[1]=false;
			}
			if(base[0]){
				point++;
				base[0]=false;
			}
		}
		/*for(int i=0;i<3;i++){
			if(base[i])printf("YES ");
			else printf("NO ");
		}
		printf("\n");
		*/
	}
    return 0;
}