#include<iostream>
#include<string>
using namespace std;

int main()
{
	int base[4]={},out_count=0,point=0;
	int count;
	string event;
	cin >> count;
	
	while(count){
		cin >> event;
		
		if(event == "HIT"){
			for(int i=3;i>=0;--i){
				base[i+1] += base[i];
				base[i] = 0;
			}
			++base[0];
		}
		
		if(event == "HOMERUN"){
			base[3] = base[0]+base[1]+base[2]+1;
			base[0] = 0;
			base[1] = 0;
			base[2] = 0;
		}
		
		if(event == "OUT"){
			++out_count;
		}
		
		if(out_count != 3){
			point += base[3];
			
		}else{
			--count;
			point = 0;
			out_count = 0;
			base[0] = 0;
			base[1] = 0;
			base[2] = 0;
			cout << point << endl;
		}
		
		base[3] = 0;
	}
	
	return 0;
}