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

int main(){
	int n;
	cin>>n;

	for(int i=0; i<n; i++)
	{
		int out=0,bass=0,point=0;
		string s;

		while(cin>>s)
		{
			if( s=="HIT") bass++;
			else if( s=="OUT" ) out++;
			else {
				point += bass+1;
				bass=0;
			}

			if( bass == 4 ) {
				point++;
				bass=bass-1;
			}
			if( out == 3 ) break; 
		}
		cout<<point<<endl;
	}

	return 0;
}